python - 击中/static/位置时不提供 index.html

标签 python ubuntu nginx flask

我正在关注 realpython article about running Flask on Ubuntu .建议在文章中检查 nginx 已通过导航到 http://localhost:8000/static 正确配置网址。它给了我 404 .

如果导航 http://localhost:8000/static/index.html index.html 已提供。我在 上都测试过Ubuntu 热情 值得信赖 并得到相同的 404 结果。这是设计使然还是错误?

这是文章中的配置:

server {
    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /static {
        alias  /home/www/flask_project/static/;
    }
}

最佳答案

不,它没有这么说。

在您的配置中,端口 8000 由 gunicorn 提供服务,而不是由 nginx 提供服务。 nginx 代理到该端口的/下的 URL - 除了/static/您已设置为直接由 nginx 提供服务。

正如教程所说,要查看静态文件,您应该直接转到默认端口上的 URL,即 80:http://localhost/static/index.html .

关于python - 击中/static/位置时不提供 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44263113/

相关文章:

python - 如何在另一个Windows 10上部署Python Flask应用程序?

php - 如何使用 AWS/nginx/Zend 制作站点到站点 VPN

python - 查找数据框中每一行的出现次数

python excel csv 帮助。如何进行格式化

python - 如何将 JSON 字符串转换为 Python 中的字典?

php - PHP脚本中的Mysql错误

linux - (ONIE) stg : command not found and Error 127 in Ubuntu terminal

git - 在 webroot 目录而不是 ~/.ssh 中克隆时权限被拒绝(公钥)

ruby-on-rails - 未定义的方法 `path_separator' 用于 Gem :Module

linux - 允许从一个站点播放 rtmp(带有 rtmp 模块的 nginx)