最佳答案
我需要服务我的应用程序通过我的应用服务器在8080
,我的静态文件从一个目录,而不接触应用程序服务器。
# app server on port 8080
# nginx listens on port 8123
server {
listen 8123;
access_log off;
location /static/ {
# root /var/www/app/static/;
alias /var/www/app/static/;
autoindex off;
}
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
现在,有了这个配置,一切工作正常。注意,root
指令被注释掉了。
如果我激活root
并停用alias
,它将停止工作。然而,当我从root
中删除后面的/static/
时,它又开始工作了。
有人能解释一下这是怎么回事吗?