[转]关于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、最后需要注意的是,修改了配置文件需要重新启动服务器,好让服务器重新加载修改后的配置文件。
进行访问。今天我解压好了一个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、最后需要注意的是,修改了配置文件需要重新启动服务器,好让服务器重新加载修改后的配置文件。