nginx+nodejs
阿神
阿神 2017-05-16 17:13:10
0
1
416

下面这个第一个location是把http://localhost:1337/gek/转给node处理
那下面第二个location是干吗的,是处理后端传过来的接口吗?
不太明白!!!

server {
   listen   80;
   server_name gek.show.com;

   location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass   http://localhost:1337/gek/;
    }

    location ~ ^/okc/rest{
        proxy_store off;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        proxy_set_header Host "gek.show.com"; 
        #proxy_pass http://gek.show.com;
        proxy_pass http://gek.show.com:8080;
    }
}
阿神
阿神

闭关修行中......

全部回复(1)
黄舟

应该这么说,第一个location是把gek.show.com域名的80端口请求默认转发给http://localhost:1337/gek/去处理,如果请求的path符合第二个location的正则那么就会把请求转发给http://gek.show.com:8080去处理,比如说请求http://gek.show.com/okc/rest/test.html就会转发给第二个location去处理.

  • ~ #波浪线表示执行一个正则匹配,区分大小写

  • ^~ 则只匹配该规则,nginx停止搜索其他匹配,否则nginx会继续处理其他location指令

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!