【问题标题】:How to make TOMCAT accessible only localhost except one app如何使 TOMCAT 只能访问本地主机,除了一个应用程序
【发布时间】:2019-06-28 08:17:46
【问题描述】:

我正在运行 TOMCAT 服务器。出于安全原因,我必须仅限制对 localhost 的访问,但必须从外部(任何 IP)访问一个应用程序。我尝试使用放置在 server.xml 中的阀门,但我只能阻止对特定功能/应用程序的访问,例如主机管理器。

如何限制除一个应用程序之外的所有应用程序?

编辑: server.xml 中的这一行会阻止除 localhost 之外的所有内容:

<Server>
<Service>
<Engine>
<Host>

...

<Valve className="org.apache.catalina.valves.RemoteAddrValve" 
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"/>

</Host>
</Engine>
</Service>
</Server>

如何为必须从外部访问的应用添加例外?

提前感谢您的帮助:-)

【问题讨论】:

  • 您可以使用引擎和主机编写一个非常不同的配置,然后在正确的主机上发布您想要的 web 应用程序,而不是 Valve。
  • 你能扩展你的建议或提供一个例子吗? :-)

标签: tomcat tomcat-valve


【解决方案1】:

您需要 2 个目录来存储不同的 web 应用程序,并且最小配置如下所示,其中 serverhost 是您网络上已知的服务器名称:

<Service name="internal">
  <Connector port="8081" protocol="HTTP/1.1" address="localhost" />
  <Engine name="Engine1internal" defaultHost="localhost">
    <Host name="localhost" appBase="webapps1"></Host>
  </Engine>
</Service>

<Service name="exposed">
  <Connector port="8080" protocol="HTTP/1.1" address="192.168.1.2"/>
  <Engine name="Engine2exposed" defaultHost="serverhost">
    <Host name="serverhost" appBase="webapps2"></Host>
  </Engine>
</Service>

当然,如果您想保留 webapps 目录,只需创建一个目录来存储另一个应用程序。我没有测试但改编自另一个配置,所以如有必要,请随时评论/编辑我的答案。

【讨论】:

  • 谢谢,我会检查并告诉你:-)
猜你喜欢
  • 2022-07-25
  • 2018-05-28
  • 1970-01-01
  • 1970-01-01
  • 2017-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-17
相关资源
最近更新 更多