我正在尝试根据 IP 地址限制可以在我的 tomcat 服务器上访问的 URL。我想要做的是允许通过环回地址(即本地主机)访问tomcat时访问任何地方,并且只允许访问所有其他远程IP的某些区域。我在 conf/web.xml 中有以下两个过滤器,但它们的行为不像我想要的那样。现在所有远程访问都被拒绝(不是我想要的)并且所有本地访问都被允许(我想要的)。我无法让 tomcat 允许所有 IP 地址访问 /terms/ 、 /help/等。
任何指针都非常感谢。
<!-- ================== Built In Filter Definitions ===================== -->
<filter>
<filter-name>Restrict Remote Filter</filter-name>
<filter-class>org.apache.catalina.filters.RemoteAddrFilter</filter-class>
<init-param>
<param-name>allow</param-name>
<param-value>\d+\.\d+\.\d+\.\d+</param-value> <!-- for any IP address, * not allowed here -->
</init-param>
</filter>
<filter-mapping>
<filter-name>Restrict Remote Filter</filter-name>
<url-pattern>/terms/*, /help/*, /messagebroker/*</url-pattern> <!-- allow access to these areas only -->
</filter-mapping>
<filter>
<filter-name>Allow Localhost Filter</filter-name>
<filter-class>org.apache.catalina.filters.RemoteAddrFilter</filter-class>
<init-param>
<param-name>allow</param-name>
<param-value>127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1</param-value> <!-- for localhost access… -->
</init-param>
</filter>
<filter-mapping>
<filter-name>Allow Localhost Filter</filter-name>
<url-pattern>/*</url-pattern> <!-- access all areas -->
</filter-mapping>