【问题标题】:Tomcat RemoteIpFilter configuration in web.xml vs server.xmlweb.xml 与 server.xml 中的 Tomcat RemoteIpFilter 配置
【发布时间】:2018-08-23 16:26:25
【问题描述】:

我在 web.xml 中设置 RemoteIpFilter 时遇到问题:我在 web.xml 中放置了以下设置:

<filter>
    <filter-name>RemoteIpFilter</filter-name>
    <filter-class>org.apache.catalina.filters.RemoteIpFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>RemoteIpFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

当我使用 HTTPS 标头向服务器发送请求时,没有“安全”标志。

但是如果我把

<Valve className="org.apache.catalina.valves.RemoteIpValve"
      remoteIpHeader="x-forwarded-for"
      protocolHeader="x-forwarded-proto"
      protocolHeaderHttpsValue="https" />

在 server.xml 中,同样的请求,我得到了“安全”标志。

我们更喜欢在 web.xml 中为每个应用程序设置配置。不知道为什么它在 web.xml 中不起作用 - 我按照 tomcat 配置文档 https://tomcat.apache.org/tomcat-8.5-doc/config/filter.html#Basic_configuration_to_handle_'x-forwarded-for'and'x-forwarded-proto 中的指示设置它p>

有人知道吗?提前致谢。

【问题讨论】:

    标签: tomcat tomcat8 web.xml server.xml


    【解决方案1】:

    将其添加到 XML:

    <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>
    

    【讨论】:

    • Tomcat 8.5.40(2019 年 4 月)引入了 X-Forwarded-Proto 作为 protocolHeader 属性的默认值,因此这个问题中的问题不再适用于最新版本的 Tomcat。
    猜你喜欢
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 2023-03-19
    • 2017-06-19
    • 2021-03-03
    • 2016-08-13
    相关资源
    最近更新 更多