在 Java Web 应用程序中处理 X-FORWARDED-PROTO 标头
任何人都可以指导我使用 X-部署到 Apache Tomcat 的 Java Web 应用程序中的 FORWARDED-PROTO 标头。
应用程序设置的方式是,tomcat 与 Apache Web 服务器通信,Apache Web 服务器又与 Cisco 负载均衡器通信,最后均衡器将页面发布到客户端(tomcat -> apache2 -> 负载均衡器 -> 客户端)。
SSL 证书安装在负载均衡器中,并且正在处理 HTTPS 请求。我的要求是让应用程序以使用 X-FORWARDED-PROTO 的方式运行,并将页面更改为 HTTP 或 HTTPS。
检查我网页的标头文件,我找不到 X-FORWARDED-PROTO 标头。我也无权访问负载均衡器配置,IT 建议我们使用 X-FORWARDED-PROTO 来区分 HTTP 和 HTTPS 请求。
是否需要在 Tomcat 或 Apache 级别进行任何配置,以便返回 X-FORWARDED-PROTO 标头?或者配置应该在负载均衡器中处理?
Can any one guide me in working with X-FORWARDED-PROTO header in Java web application deployed to Apache Tomcat.
The application setup is in such a way that tomcat talks with Apache webserver, which in turn talks with Cisco Load Balancer, finally the balancer publishes the pages to the client (tomcat -> apache2 -> load balancer -> client).
The SSL Certificate is installed in Load Balancer and it's handling HTTPS requests. My requirement is to make the application behave in such a way that it uses the X-FORWARDED-PROTO and change the pages as HTTP or HTTPS.
Checking on the header files of my webpages I could not find the X-FORWARDED-PROTO header. I don't have access to the Load Balancer configuration either, and the IT has suggested us to use the X-FORWARDED-PROTO to differentiate between HTTP and HTTPS request.
Is there any configuration to be done in Tomcat or Apache level so that it will return the X-FORWARDED-PROTO header? Or is it that the configuration should be handled in Load Balancer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很确定您现在已经弄清楚了,但我仍然会添加答案。
您可以在tomcat的conf/server.xml中的引擎标签中使用类org.apache.catalina.valves.RemoteIpValve。
需要注意的是,设置 internalProxies 值非常重要。如果未设置此选项并且您使用非标准网络设置,则可能会导致一些问题,其中 tomcat 不会检查 x-forwarded 标头,并且默认为“http”。出于安全原因,我建议设置它,即使它适用于默认值。
请参阅此处了解更多信息。
I am pretty sure you have it all figured out by now but I will add the answer nonetheless.
You can use the class org.apache.catalina.valves.RemoteIpValve in the engine tag in conf/server.xml of tomcat.
Something to note that is very important is to set the internalProxies value. If this is not set and you are you using a non-standard network setup it could cause some issues where tomcat will not check for x-forwarded headers and it will default to "http". For security reasons I'd recommend to set it even if it works with the defaults.
Look here for more information.
将其添加到您的 apache vhost 管理连接中,
假设您的健康检查是 /status,这不需要 https
Add this to your apache vhost managing connections
this assumes your health check is /status, which doesn’t require https