amazon-web-services - AWS Application Load Balancer 未传递 x-forwarded-for header

标签 amazon-web-services tomcat amazon-ec2 elastic-load-balancer

我的 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-ForX-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/

相关文章:

amazon-web-services - AWS通过cloudformation启用EBS加密

amazon-ec2 - 亚马逊 AWS : How Do I Programmatically Calculate My Spending?

c# - Dotnet-core默认使用2.0框架ubuntu

tomcat - 无法在 maven 中使用 broadleaf 运行 Tomcat 服务器

performance - 如何使用 Amazon Simple Notification Service (SNS) 批量发送数百万个推送通知

java - 在 tomcat docker 上部署 java REST 服务

mysql - Tomcat/hibernate 配置

amazon-ec2 - 获取 EC2 实例 Java API 的状态

.net - 在 Azure 上运行 .NET 应用程序

java - AWS Corretto 示例应用程序源