无法访问 Tomcat 8 个管理器应用

Can't access Tomcat 8 Manager App

我刚刚在 Ubuntu 14.04 VM 上设置了 Tomcat 8,但我无法从浏览器访问 http://[hostname]:8080/manager/html 上的管理器应用程序。我一点击它就收到“403 Access Denied”错误。我正在 运行ning Tomcat 作为在 /etc/init.d/tomcat8-dev 的配置文件中定义的服务。错误消息表明 Tomcat 最初设置为只能从本地主机访问,但由于它是托管 VM,我无法 运行 浏览器。

我已经按照几个人的建议在 tomcat-users.xml 文件中设置了一个用户。但是,系统没有提示我为该用户提供凭据,而且我在默认页面上找不到任何类型的登录按钮。该文件目前看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
    version="1.0">

    <role rolename="manager-script"/>
    <role rolename="manager-jmx"/>
    <role rolename="manager-gui"/>
    <role rolename="manager-status"/>

    <user username="(redacted)" password="(redacted)" 
        roles="manager-gui,manager-jmx,manager-status,manager-script"/>
</tomcat-users>

阅读 Tomcat 文档页面 here 后,我还尝试将 <Valve /> 标签添加到 context.xml 中,看起来像这样:

<Context privileged="true" antiResourceLocking="false"
    docBase="${catalina.home}/webapps/manager">

    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.0\.0\.1" />
    <!--Another valve for my local machine's IP-->

</Context>

但是,一旦我设置 privileged="true",当我使用浏览器连接到服务器时,无论我之后提供的阀门如何,我都会得到一个空白页面。

每当我进行更改时,我都会使用 sudo service tomcat8-dev restart 重新启动我的服务。

根据我在此处和其他网站上阅读的帖子,我尝试过的其他事情:

我试过的都没有用。如果您想了解有关我的情况的更多详细信息,请告诉我。有什么建议吗?

编辑: 问题是我编辑了错误的 context.xml 文件。正确的文件在 tomcat/webapps/manager/META-INF 中。我错误地更改了 tomcat/conf/context.xml.

你应该改变:

docBase="${catalina.home}/webapps/manager"

至:

docBase="${catalina.base}/webapps/manager"

这是因为您没有使用从上游分发的 Tomcat,而是 Ubuntu.

附带的那个

AFAIK Tomcat 阻止所有主机访问管理器应用程序 (manager/html),但默认配置中的 localhost 除外。

为了能够使用 http://[hostname]:8080/manager/html 访问管理器 GUI,请在配置文件 server.xml[=经理应用程序的 65=]

步骤 1: 在 [tomcat-install-dir]/conf/server.xml 中编辑 Connector 元素并添加您的 IP 以及 useIPVHosts="true",即:

<Connector port="9009" protocol="AJP/1.3" redirectPort="9443" 
           address="192.168.0.9" useIPVHosts="true" />

address="0.0.0.0" 可能不是您想在此处插入的内容,因为它将管理器 GUI 暴露给网络上的所有机器。

步骤 2: 在 [tomcat-install-dir]/webapps/manager/META-INF/context.xml 中,编辑 Valve 元素并添加您的 IP:

<Context antiResourceLocking="false" privileged="true">

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

来自Tomcat 8 context documentation

privileged : Set to true to allow this context to use container servlets, like the manager servlet.

antiResourceLocking : If true, Tomcat will prevent any file locking. This will significantly impact startup time of applications, but allows full webapp hot deploy and undeploy on platforms or configurations where file locking can occur

请注意,我没有像您在尝试的事情列表中提到的那样添加另一个 Valve 元素,而是编辑现有的元素并仅添加我的 IP (192.168.0.9)。

第 3 步: 重新启动 Tomcat 并且您应该能够使用本地主机/127.0.0.1 以及您的主机名/IP 访问管理器 GUI。


注意

关于您的 tomcat-users.xmlTomcat Manager HOW-TO 指出:

It is recommended to never grant the manager-script or manager-jmx roles to users that have the manager-gui role.

所以您可能想在 tomcat-users.xml 中引入两个用户,即:

  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <role rolename="manager-gui"/>
  <role rolename="manager-status"/>
  <user username="alice" password="whatever" roles="manager-script,manager-jmx"/>
  <user username="bob" password="whatever" roles="manager-gui,manager-status"/>

我认为这可能对你们所有人都有帮助,因为它对我有用。

这里我使用的是 Apache tomcat 8:

root@akash-LIFEBOOK-A555:/opt/apache-tomcat-8.5.20/bin# ./version.sh 
Using CATALINA_BASE:   /opt/apache-tomcat-8.5.20
Using CATALINA_HOME:   /opt/apache-tomcat-8.5.20
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.5.20/temp
Using JRE_HOME:        /DATA/jre1.8.0_131/
Using CLASSPATH:       /opt/apache-tomcat-8.5.20/bin/bootstrap.jar:/opt/apache-tomcat-8.5.20/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.20
Server built:   Aug 2 2017 21:35:49 UTC
Server number:  8.5.20.0
OS Name:        Linux
OS Version:     4.4.0-98-generic
Architecture:   amd64
JVM Version:    1.8.0_131-b11
JVM Vendor:     Oracle Corporation

编辑 tomcat-user.xml 并添加角色和用户

<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="admin-gui"/>
<user username="admin" password="password" roles="manager-gui,manager-status,manager-script,manager-jmx,admin-gui"/>

我也遇到了同样的问题,我首先在 config/tomcat-users.xml 中添加了角色用户和密码,然后在 webapps/manager/META-INF/context.[= 中允许了我的 public ip 15=] 最初添加本地 ip 127 以供来自同一台机器的使用管理器。添加你的ip

如果你想在所有机器上访问管理器应用程序,你可以简单地做。转到 {Tomcat_install_DIR}/webapps/manager/META-INF/ 并编辑 context.xml 放入

<Context antiResourceLocking="false" privileged="true" >
 <!--
 <Valve className="org.apache.catalina.valves.RemoteAddrValve" 
  allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  -->
</Context>

更新'apache-tomcat-8.5.5\webapps\manager\META-INF\context.xlm 文件。取消注释值标记。并重启服务器

context.xml 文件

Before : 

<Context antiResourceLocking="false" privileged="true">
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
     allow="192\.168\.0\.9|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
</Context>

After change :

<Context antiResourceLocking="false" privileged="true" >
</Context>

for auto deployment: go to 'apache-tomcat-8.5.5\conf\context.xml' and add antiResourceLocking="true" in 'Context' tag

对我来说,除了在 tomcat-users.xml 中放置具有管理员角色的管理员用户外,我还必须修改管理员和主机的 2 个 /META-INF/context.xml 文件- /webapps 下的管理器应用程序,具有以下内容: 127 -> \d+ 因此将使任何外部电脑的浏览器访问其管理站点