我正在关注 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/