[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]nginx的x-forwarded-proto引起的端口丢失

上一篇:[转帖]Nginx反向代理至非80端口时丢失端口
下一篇:[备忘]spring的properties value 注入时,使用默认值

添加日期:2021/2/24 19:22:00 快速返回   返回列表 阅读771次
nginx反向代理到tomcat,
使用proxy_set_header Host $host:$server_port; 可以把端口带过去,
但是,发现Request.getServerPort()总是返回80端口,而不是访问nginx的6000端口。
------------
debug发现,port值开始是6000,后来变成了80。
继续debug发现,判断了Header项目:protoHeader,
如果是https,port变为443,如果是http,port变成80.
------------
查看nginx配置文件,发现写了
proxy_set_header X-Forwarded-Proto  $scheme; 
去掉,问题解决。
--------------------------------------------
The X-Forwarded-Proto (XFP) header is a de-facto standard header for identifying the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer. 
Your server access logs contain the protocol used between the server and the load balancer, but not the protocol used between the client and the load balancer. 
To determine the protocol used between the client and the load balancer, the X-Forwarded-Proto request header can be used.
--------------------------------------------
另外,可以参考这个:
https://tomcat.apache.org/tomcat-8.5-doc/config/filter.html
可以配置RemoteIpFilter,获取remote端的原始ip和端口
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved