[轉]關於tomcat 中的 tomcat-users.xml 配置不生效原因


安裝完tomcat,或者解壓完tomcat后,在tomcat的目錄下有個conf文件夾,在這個文件夾下面有一個tomcat-
users.xml的文件,這個文件里面的配置信息是當我們進入http://localhost:8080 頁面后,有些功能需要登錄才能

進行訪問。今天我解壓好了一個tomcat,環境變量也配置好了,啟動服務也沒問題,就是登錄不進去Manager App,大

概花了我一個下午的時間才解決這個問題。
  首先tomcat-users.xml這個文件就是tomcat提供給我們進行登錄用戶的配置,但是一開始我配置了很多次也不成功
,在網上也查了很多方法沒用,接下來我將說明一下如何配置這個用戶。
  1、首先你確定在conf目錄下的server.xml文件有
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource auth="Container" description="User database that can be updated and saved" 
factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" 
pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>
這樣一段代碼,讓tomcat啟動服務后能加載到conf/tomcat-users.xml,這個文件。
  2、新解壓的tomcat下的tomcat-users.xml,中的user全部都是被注釋掉的
<tomcat-users>
<!--
  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"/>
-->
</tomcat-users>
我們需要把那個注釋去掉才能是的user生效,有很多人在這個地方犯錯,注釋不去掉,那都是沒用的。
  3、注意在配置username的時候,不要取重復的名字,因為這樣很可能讓你的配置不起效果。
  4、使用tomcat7.X版本的朋友們注意了,這也是今天下午被坑的原因,tomcat7.X的user配置是有一定的規定的,


不能隨意更改,你改成其他的很有可能不會生效,本人親測,原來各種網上百度,找了很多種的配置方法就是沒效果,


結果我將user配置改成如下結果終於登錄進去了。
<?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>
<!--
  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"/>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui,admin-gui"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>


</tomcat-users>
  5、最后需要注意的是,修改了配置文件需要重新啟動服務器,好讓服務器重新加載修改后的配置文件。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM