首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx的port_in_redirect配置

nginx的port_in_redirect配置

作者头像
code4it
发布2018-09-17 15:42:27
2K0
发布2018-09-17 15:42:27
举报
文章被收录于专栏:码匠的流水账码匠的流水账

本文主要讲解下port_in_redirect的实际用途。

场景

有一个80端口的nginx,要转发一个路径到另一个8080端口的nginx,配置如下

server {
        listen       80  default_server;
        server_name demoapp.com.cn;
        location /public/ {
            proxy_pass http://192.168.99.100:8080/public/ ;
        }
}

另外一个nginx的配置如下

server {
        listen       8080  default_server;
        location ~* /public/(share|webview) {
            root   html ;
            proxy_buffering off;
            index  index.html index.htm;
        }
}

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就派上用场了。

server {
        listen       8080  default_server;
        location ~* /public/(share|webview) {
            root   html ;
            proxy_buffering off;
            port_in_redirect off;
            index  index.html index.htm;
        }
}

通过指定port_in_redirect off;告知nginx在redirect的时候不要带上port,如果没有配置,默认该值为true

doc

  • port_in_redirect
  • Nginx中的server_name_in_redirect和port_in_redirect指令
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-01-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码匠的流水账 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 场景
  • 问题
  • doc
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档