我的 tomcat 应用程序没有从 AWS 应用程序负载均衡器接收 X-Forwarded-For header 。负载平衡器配置为卸载 SSL 并通过 HTTP 连接到 tomcat 应用程序。我收到其他 header ,例如 x-forwarded-proto、x-forwarded-port、x-amzn-trace-id。我正在尝试查找客户端 IP 地址,但现在坚持使用它。我还检查了我收到的所有 header 以找出客户端 IP 地址,但它不存在。谁能帮帮我?
最佳答案
这可能与 tomcat 配置有关。检查您是否在 tomcat 中获得了以下配置来处理 X-Forwarded-For
和 X-Forwarded-proto
header
<filter>
<filter-name>RemoteIpFilter</filter-name>
<filter-class>org.apache.catalina.filters.RemoteIpFilter</filter-class>
<init-param>
<param-name>protocolHeader</param-name>
<param-value>x-forwarded-proto</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>RemoteIpFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
这是配置引用:https://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Basic_configuration_to_handle_ “x-forwarded-for”和“x-forwarded-proto”
您可以在 $CATALINA_BASE/conf/web.xml
或应用程序的 WEB-INF/web.xml 中找到配置文件
Tomcat provides a number of Filters which may be configured for use with all web applications using $CATALINA_BASE/conf/web.xml or may be configured for individual web applications by configuring them in the application's WEB-INF/web.xml.
关于amazon-web-services - AWS Application Load Balancer 未传递 x-forwarded-for header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48125897/