有一个80端口的nginx,要转发一个路径到另一个8080端口的nginx,配置如下
<code>server { listen 80 default_server; server_name demoapp.com.cn; location /public/ { proxy_pass http://192.168.99.100:8080/public/ ; }}/<code>
另外一个nginx的配置如下
<code>server { listen 8080 default_server; location ~* /public/(share|webview) { root html ; proxy_buffering off; index index.html index.htm; }}/<code>
html目录里头有个public目录,public目录里头有share以及webview目录,存放各个子模块的静态资源。
问题
这样配置了之后,通过demoapp.com.cn/public/share访问的时候,会跳转到demoapp.com.cn:8080/public/share
假设这两个nginx监听同一个ip,如果不是同一个ip,估计要配置server_name以及开启server_name_in_redirect
这个时候,port_in_redirect就派上用场了。
<code>server { listen 8080 default_server; location ~* /public/(share|webview) { root html ; proxy_buffering off; port_in_redirect off; index index.html index.htm; }}/<code>
通过指定port_in_redirect off;告知nginx在redirect的时候不要带上port,如果没有配置,默认该值为true
参考文章:
http://nginx.org/en/docs/http/ngx_http_core_module.html#port_in_redirect
https://blog.csdn.net/weiyuefei/article/details/38556593
查看更多
閱讀更多 運維小筆記 的文章