nginx,tomcat环境中 redirect的问题

场景:

 

nginx监听9999端口,转发到tomcat监听的8080端口。
比如客户请求:http://10.232.128.168:9999  这个登陆页面。
在客户登陆之后,redirect到相对路径/home.do。
此时,客户的请求地址是:http://10.232.128.168/home.do ,端口号没有了。
这个时候访问失败,必须在手动加上端口号才能访问,即:http://10.232.128.168:9999/home.do .

解决方案
 http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
nginx 写道
Sets a text that should be changed in the header fields “Location” and “Refresh” of a response from the proxied server. Suppose a proxied server returned the header field “Location: http://localhost:8000/two/some/uri/”. The directive

proxy_redirect http://localhost:8000/two/ http://frontend/one/;

will rewrite this string to “Location: http://frontend/one/some/uri/”.
      可以通过nginx的proxy_redirect模块中,重写response中的Location,让客户端发起请求的时候请求的是重写过后的地址。所以在我配置项中,只需要加入:proxy_redirect http://10.232.128.168 http://10.232.128.168:9999;
即可解决问题。

注意:如果tomcat模块的配置被主配置include的时候,注意全文搜索下proxy_redirect off; 如果主配置关闭了这个模块,那么你在include里面配置是不会起作用的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值