web.xml和server.xml中的T​​omcat RemoteIpFilter配置

时间:2018-08-23 16:26:26

标签: tomcat tomcat8 web.xml server.xml

我在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''x-forwarded-proto中的指示进行设置

有人对此有任何想法吗?预先感谢。

1 个答案:

答案 0 :(得分: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>
相关问题