Nginx反向代理服务器获取不到端口的问题的解决办法

使用nginx为反向代理服务器时,后端应用程序获取不到请求端口的解决办法。 

以下是nginx 简单的配置 
server { 
        listen       81; 
        server_name  localhost; 
        location / { 
          proxy_set_header Host $host; 
          proxy_set_header X-Forwarded-For $remote_addr; 
          proxy_pass http://127.0.0.1:9380; 
        } 


把第5行 的 proxy_set_header Host $host; 修改为  proxy_set_header Host $host:$server_port; 即可。 

原因是$host参数不包含端口号导致请求头部Host中的端口号丢失从而使后端程序不能正确的获取端口号。 

使用 CXF 实现webservice 时 通过nginx 反向代理 动态生成的wsdl文件中 location地址中的端口号也会丢失,从而导致 webservice 调用失败。 

$host 参数的解释 
This variable is equal to line Host in the header of request or name of the server processing the request if the Host header is not available. 

This variable may have a different value from $http_host in such cases: 1) when the Host input header is absent or has an empty value, $host equals to the value of server_name directive; 2)when the value of Host contains port number, $host doesn't include that port number. $host's value is always lowercase since 0.8.17. 

转载于:https://www.cnblogs.com/Leslieblog/p/10138421.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值