惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 是谁啊?

jenkins 权限控制(用户只能看指定的项目) NoSQLBooster for MongoDB延长-试用期 使用openVPN组建企业局域网,连接之后无法访问互联网的问题解决 - 是谁啊? mac os socks5转http proxy M1 Mac Xcode模拟器无法运行 解决git“Unable to negotiate with 218.244.143.137 port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss”的问题 macos 升级后提示 python 命令需要使用命令行开发者工具,你要现在安装该工具吗 解决 Android studio 代理 Connect to 127.0.0.1:[/127.0.0.1] failed: Connection refused centos6无法安装nginx Postfix maillog邮件发送各阶段延时的日志记录 高德坐标系转wgs(苹果坐标系) java代码 How Do I test James Distributed Version with JMeter? springBoot项目不重新上传jar包,增量升级步骤 mac安装homebrew(国内) 企业微信会话存档消息解密(Java RSA PKCS1解密) 启动apache,将debug日志输出在console窗口 转:solr6.0配置中文分词器IK Analyzer git 忽略提交某个指定的文件(不从版本库中删除) git pull 和本地文件冲突问题解决
nginx 代理https后,应用redirect https变成http
是谁啊? · 2021-07-06 · via 博客园 - 是谁啊?

nginx配置https,tomcat正常http接受nginx转发。
nginx 代理https后,(java代码redirect地址)应用redirect https变成http

情况类似

http://2hei.net/mt/2010/02/request-getscheme-cannt-get-https.html

http://yywudi.info/nginx-https-400-bad-request-solution/

原因分析:

经过nginx代理后用的spring mvc的redirect,

其中: request.getScheme() return http but not https.

浏览器调整的地址变成http

解决办法:http://han.guokai.blog.163.com/blog/static/136718271201211631456811/

在代理模式下,Tomcat 如何识别用户的直接请求(URL、IP、https还是http )?
在透明代理下,如果不做任何配置Tomcat 认为所有的请求都是 Nginx 发出来的,这样会导致如下的错误结果:

   request.getScheme()  //总是 http,而不是实际的http或https
   request.isSecure()  //总是false(因为总是http)
   request.getRemoteAddr()  //总是 nginx 请求的 IP,而不是用户的IP
   request.getRequestURL()  //总是 nginx 请求的URL 而不是用户实际请求的 URL
   response.sendRedirect( 相对url )  //总是重定向到 http 上 (因为认为当前是 http 请求)

如果程序中把这些当实际用户请求做处理就有问题了。解决方法很简单,只需要分别配置一下 Nginx 和 Tomcat 就好了,而不用改程序。
配置 Nginx 的转发选项:

proxy_set_header      Host $host;
proxy_set_header  X-Real-IP $remote_addr;
proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto  $scheme;

配置Tomcat server.xml 的 Engine 模块下配置一个 Value:
<Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https"/>

配置双方的 X-Forwarded-Proto 就是为了正确地识别实际用户发出的协议是 http 还是 https。X-Forwarded-For 是为了获得实际用户的 IP。
这样以上5项测试就都变为正确的结果了,就像用户在直接访问 Tomcat 一样。

后记:
上面https到http解决办法对context引导还是会出问题,
比如输入https://xxxx/signet 会转向到http://xxx/signet/ ,
http情况下:输入http://xxxx/signet会返回一个302到http://xxxx/signet/然后正常访问。