我有一个运行gunicorn -w 1 -b 0.0.0.0:8000 flaskapp:app的flask应用程序,其nginx配置如下.但是,如何判断nginx是否实际在提供静态文件?我尝试更改别名/ home / pi / Public / flaskapp / static /; … … /静态测试/;并仅在其中放置一个占位符style.css,但页面似乎像以前一样加载.
server {
listen 5000;
server_name _;
location / {
proxy_pass http://127.0.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /static {
alias /home/pi/Public/flaskapp/static/;
}
}
我是否缺少明显的东西?是否必须在烧瓶的路径中指定某些内容?
解决方法:
因此,我终于正确配置了nginx.我添加了root并删除了static的硬路径,还添加了日志文件,这些文件清楚地表明从nginx加载了static和CSS!我还将监听端口更改为80(备用).
server {
listen 80;
server_name myapp.com;
root /home/pi/Public/myapp;
access_log /home/pi/Public/myapp/logs/nginx-access.log;
error_log /home/pi/Public/myapp/logs/nginx-error.log;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /static/ { }
location /uploads/ { }
}