我的配置看起来像: 1)
server {
listen 80;
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-deploy/project/static/;
}
}
2)更新
server {
listen 8080;
server_name mysite.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /static/ {
root /home/www/flask-deploy/blog;
}
}
更新了问题:
如果我查看mysite.com:8080/static/css/main.css
,我可以看到这一点,但如果我访问mysite.com:8080
,则会显示#1
的内容而不是#2
答案 0 :(得分:0)
第一个配置包括alias
指令,第二个配置包含root
。所以,这就是他们行为不同的原因。以下是两种配置中匹配URI和实际路径的示例:
<强> 1 强>
location /static {
alias /home/www/flask-deploy/project/static/;
}
http://somehost:80/static/somefile
- &gt; /家庭/网络/瓶部署/项目/静态/ somefile
http://somehost:80/static/dir/somefile
- &gt; /家庭/网络/烧瓶部署/项目/静态/目录/ somefile
<强> 2 强>
location /static/ {
root /home/www/flask-deploy/blog/static;
}
http://somehost:8080/static/somefile
- &gt; /家庭/网络/烧瓶部署/博客/静态/的静态强> / somefile
http://somehost:8080/static/dir/somefile
- &gt; /家庭/网络/烧瓶部署/博客/静态/的静态强> /目录/ somefile