`
gigi_112
  • 浏览: 113217 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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里面配置是不会起作用的。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics