可以将nginx中的location指令与端口号匹配吗?

时间:2016-01-29 21:49:37

标签: nginx flask

我的配置看起来像: 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

1 个答案:

答案 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