问题描述
下面这个第一个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指令