欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker下通过Kitematic创建Tomcat8 image 无法访问Manager App页面

程序员文章站 2024-03-25 17:16:52
...

当我通过Kitematic创建一个Tomcat8的image之时, Startup tomcat,尝试访问admin page但是失败.尝试更改tomcat-users.xml,但未生效,一直显示以下错误:

Docker下通过Kitematic创建Tomcat8 image 无法访问Manager App页面

查看conf/server.xml,内容如下:

  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

由此可见,tomcat是要从tomcat-users.xml里读取用户信息的.但是还是依然不生效.

继续查看conf/context.xml

<Context>

    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
</Context>

修改conf/tomcat-users.cml

<?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">
<role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <role rolename="manager-status"/>
  <role rolename="admin"/>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="admin" password="admin" roles="admin,manager,manager-gui,manager-script,manager-jmx,manager-status"/>
</tomcat-users>

解决方法:

在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,这时应该可以访问 Manager App页面了.