Tomcat 8管理应用程序未提示输入用户名和密码,返回403访问被拒绝。

67

我按照这个链接的说明安装了Tomcat 8,并且拥有以下的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-gui"/>
  <role rolename="manager-script"/>

  <user username="notadmin" password="not_real_pass" roles="manager-gui"/>
  <user username="cargo" password="not_real_pass" roles="manager-script"/>
<tomcat-users/>

当我尝试访问管理应用程序时,我会被拒绝并收到403错误,没有提示输入用户名和密码。

我在配置中漏掉了什么?

编辑1:添加完整的xml文件。


我成功的方法是 mv manager manager.bak; rsync -a manager.bak manager - Sridhar Sarnobat
你可以关注这个帖子。 https://dev59.com/rVoV5IYBdhLWcg3wGbjT#57746102 - Md. Sajedul Karim
17个回答

177

这可能是有效的工作。

找到CATALINA_HOME/webapps/manager/META-INF/context.xml文件,并在Valve周围添加注释标记。

<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>

你可以在这个页面找到更多细节。


这对我来说是个问题。我正在编辑全局context.xml(我猜被管理器应用程序内更具体的context.xml覆盖了?)。 - Salil Junior
13
这个配置有安全目的,例如它只允许从本地访问管理应用程序。你可以通过SSH隧道连接并转发Tomcat运行的端口(8080),方法是使用ssh user@tomcat-machine -L 8080:localhost:8080命令,然后不要使用http://tomcat-machine:8080而是使用http://localhost:8080来访问管理应用程序以解决此问题。 - JaKu
如果这仍然对您不起作用,请在manager.xml中进行相同的更改(您的catalina.out文件将告诉您它在哪里,例如20-Aug-2019 12:06:42.236 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor /Users/me/apache-tomcat-8/conf/Catalina/localhost/manager.xml)。 - Sridhar Sarnobat

23

对我有用的解决方案是编辑在 $CATALINA_HOME/webapps/manager/META-INF$CATALINA_HOME/webapps/host-manager/META-INF 中的 context.xml 文件,其中我的 IP 是 123.123.123.123

<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|123.123.123.123" />
</Context>

我在Ubuntu上安装了Tomcat 8.5,并编辑了$CATALINA_HOME/conf/tomcat-users.xml文件:

<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="myuser" password="mypass" roles="admin-gui,manager-gui"/>

不过,直到我编辑了context.xml文件,我仍然无法访问Tomcat Web应用程序管理器(localhost:8080/manager/html)和Tomcat虚拟主机管理器(localhost:8080/host-manager/html)。


我也在我的机器上解决了这个问题(运行Ubuntu 15.10服务器,tomcat 8.5)。我也是使用同样的教程。 - kiwicomb123
这对我有用。使用:Tomcat/8.5.14 + Ubuntu 14.04.5 LTS - aelkz
在我的情况下,使用Tomcat 9.0.78运行良好。 - Marcelo Espinosa

18

这里有一个有用的链接:访问不同主机上的Tomcat管理器应用程序

从Tomcat 8版本开始,管理器/ html网址将无法被除本地主机以外的任何人访问。

若要访问/manager/html网址,您需要在管理器应用程序的context.xml文件中进行以下更改: 1. 转到 /apache-tomcat-8.5.23/webapps/manager/META-INF 位置,然后编辑 context.xml

<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="^.*$" />
 ......
</Context>
  1. 重新启动服务器。

3
你正在使用正则表达式"^.*$"允许任何IP地址访问Tomcat管理器。你确定要允许任意IP地址访问吗? - kimbaudi

17

正确答案可以在这里找到。


看起来在Unix系统上按照所提及的教程可以重现这个问题。同时注意到作者使用的是TC 8.0.33,Win (和OSX)没有这样的问题,至少在我的环境中是这样的。

Server version:        Apache Tomcat/8.5.4
Server built:          Jul 6 2016 08:43:30 UTC
Server number:         8.5.4.0
OS Name:               Windows 8.1
OS Version:            6.3
Architecture:          amd64
Java Home:             C:\TOOLS\jdk1.8.0_101\jre
JVM Version:           1.8.0_101-b13
JVM Vendor:            Oracle Corporation
CATALINA_BASE:         C:\TOOLS\tomcat\apache-tomcat-8.5.4
CATALINA_HOME:         C:\TOOLS\tomcat\apache-tomcat-8.5.4

在向tomcat-users.xml文件添加角色和用户后,可以访问Tomcat/8.5.4上的Tomcat Web应用程序管理器


15

我需要修改以下文件:

$CATALINA_BASE/conf/Catalina/localhost/manager.xml并添加以下行:

  <Context privileged="true" antiResourceLocking="false" 
     docBase="${catalina.home}/webapps/manager">
        <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
  </Context>

这将允许从任何机器访问Tomcat,如果要授予特定IP访问权限,则使用下面的值而不是allow="^.*$"

    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192\.168\.11\.234" />

4

fade的回答对我有用。我从8.0.30升级到8.5.5,不同之处在于<8.0.30>/manager/META-INF/context.xml中的阀门已经被注释掉了,而在8.5.5 tar中则是取消了注释。

我没有读到403响应中的这条重要信息:

默认情况下,Manager只能通过运行在Tomcat上的浏览器访问。如果您希望修改此限制,则需要编辑Manager的context.xml文件。

我也没有读到这个:

自r1734267以来,在Manager和HostManager Web应用程序中默认配置了RemoteAddrValve。此功能在9.0.0.M4和8.5.0及以上版本中存在。

https://bz.apache.org/bugzilla/show_bug.cgi?id=59672


4
  1. 检查用户是否已创建, 如果没有,请在 /apache-tomcat-9.0.20/tomcat-users.xml 文件中添加以下行:

    <user username="tomcat" password="tomcat" roles="admin-gui,manager-gui,manager-script" />

  2. 前往 /apache-tomcat-9.0.20/webapps/manager/META-INF/ 目录, 打开 context.xml 文件,在 context 标签中注释所有内容。 例如:

<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>

3
如果以上方法都不起作用,确保tomcat可以访问webapps下的manager文件夹(chown ...)。这条消息是完全相同的,我花了2个小时才找出问题。:-) 仅供其他遇到相同问题的人参考。

3

将以下内容复制到文件tomcat-users.xml

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<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">
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
<role rolename="manager-gui"/>
<role rolename="manager-script"/>

<user username="notadmin" password="not_real_pass" roles="manager-gui"/>
<user username="cargo" password="not_real_pass" roles="manager-script"/>


</tomcat-users>

我已经测试过了,它可以正常工作!

输入图片描述


您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Hodossy Szabolcs
你能发布tomcat-users.xml文件的完整内容吗?(添加到问题中) - Raphaël Colantonio
我按照要求修改了问题。同时我注意到模式位置无法访问。这会是一个问题吗? - Hodossy Szabolcs
1
我看到你正在使用tomcat7,但我正在使用8.5.4。我不认为这在这个问题上会有很大的区别,但也许值得注意一下。 - Hodossy Szabolcs
哦,这是Tomcat 8.0.35(另一个选项卡是来自tomcat.apache.org的网页)。 - Raphaël Colantonio

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


Close all the session, once closed, ensure open the URL in incognito mode login again and it should start working

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接