How to restrict access by IP address with Tomcat?

2019-01-06 16:37发布

Does anyone know if Tomcat can restrict access to certain application by IP address (like Apache's .htaccess)?

4条回答
在下西门庆
2楼-- · 2019-01-06 16:40

This is an example:

in \apache-tomcat-7.0.33\conf\server.xml:

<Engine name="Catalina" defaultHost="localhost">
    ...
    ...
    ...
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
        allow="10\.132\.77\.55|10\.132\.76\.120|10\.132\.77\.47"/>
    ...
</Engine>
查看更多
贼婆χ
3楼-- · 2019-01-06 16:42

To set up access restriction to your web-application for the certain IP addresses, add the following strings to /opt/tomcat/webapps/ROOT/META-INF/context.xml file:

<Context antiJARLocking="true" path="/">
 <Valve className="org.apache.catalina.valves.RemoteIpValve" />
 <Valve className="org.apache.catalina.valves.RemoteAddrValve" deny="{IP_address}" />
</Context>

Here is the instruction how to do this via Jelastic panel.

查看更多
smile是对你的礼貌
4楼-- · 2019-01-06 16:49

You add a Valve to the Context in context.xml (specifically, org.apache.catalina.valves.RemoteAddrValve). See the docs on Remote Host Filters.

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-06 17:01

In Tomcat 7, you can configure it in the web.xml.

If it's for all web apps, you can configure it in tomcat7/conf/web.xml, if it is just for one web app, you can configure it in the tomcat7/webapps/$(WEB_APP)/WEB-INF/web.xml, it's very convenient.

The configuration uses a RemoteAddrFilter filter, there is an example in Container Provided Filters.

查看更多
登录 后发表回答