您好,欢迎来到华拓科技网。
搜索
您的当前位置:首页proxy_set_header

proxy_set_header

来源:华拓科技网

描述:浏览器访问nginx(http://10.90.3.118:80),nginx又将请求代理到了后端的springboot(http://10.90.3.119:8080),springboot中需要做302跳转,怎么让浏览器发起的跳转指向http://10.90.3.118:80。

如果直接在Java中这样获取,拿到的是springboot服务器的IP和端口:

String host = request.getServerName(); //10.90.3.119
String port = request.getServerPort(); //8080

//另外
String remoteHost = request.getRemoteHost();//10.90.3.118
String remotePort = request.getRemotePort();//44638

关于remoteHost、remotePort这里不讨论。 可见host、port是springboot服务器ip和端口。那么如何获取nginx的ip和端口呢?

可以在配置代理时添加 proxy_set_header 配置项:

 location ^~ /api {
     proxy_pass http://10.90.3.119:8080;
     proxy_set_header Host $host;
 }

再次获取host、port,就能获取成功了:

String host = request.getServerName(); //10.90.3.118
String port = request.getServerPort(); //80

 

转载于:https://my.oschina.net/u/1185936/blog/1581792

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo6.cn 版权所有 赣ICP备2024042791号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务