【发布时间】:2015-08-10 20:47:28
【问题描述】:
我正在使用这个tutorial - part 1,但我不确定如何测试该应用程序是否在使用 nginx 服务静态文件的情况下运行。
我有完全相同的代码。
/etc/nginx/sites-available/flask_project
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/;
}
}
然后:
gunicorn app:app -b localhost:8000
所有路线都运行良好。但是,如果我这样做 http://localhost:8000/static 我会看到
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
显然我应该从静态文件夹中看到带有<h1>Test!</h1> 的页面。
我做错了什么?
基本上我想知道如何配置 nginx 来提供静态文件然后确认。
-app.py
-static
-index.html
【问题讨论】:
-
您对
localhost:8000的请求完全绕过nginx 直接发送到gunicorn。您应该请求localhost/...或您用于服务器的任何名称。 -
@AlexeyTen 所以,我是否正确地提供静态文件?就是这个问题。
标签: python nginx flask webserver gunicorn