Tomcat 8.5 无法进入管理页面 manager app
报错截图
解决需要3步:
1. 添加 Context
$CATALINA_HOME/conf/Catalina/localhost/下创建 manager.xml , 填入如下内容
<Context privileged="true" antiResourceLocking="false" docBase="${catalina.home}/webapps/manager">
2. 添加用户:
$CATALINA_HOME/conf/tomcat-users.xml 中的
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>
2. 注释访问限制:
$CATALINA_HOME/webapps/manager/META-INF/context.xml
注释掉下面的内容 ,以下内容不要运行。
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> -->
完成后重启Tomcat即可
对于manager页面,在已经设置了用户和manager-gui, manager-script权限之后,仍然报403权限问题
Manager 403 Access Denied: You are not authorized to view this page.
By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you’ll need to edit the Manager’s context.xml file.
或manager/text接口:
Tomcat return http status error: 403 , Reason Phrase:(中间省略一堆html代码) The server understood the request but refuses to authorize it
这个时候只需要按照上面的提示,修改manager的context.xml文件即可,具体在manager/META-INF/context.xml,修改如下,将Value标签整个注释掉即可,无需重启tomcat(可能需要稍等几秒钟):如:上面 2. 注释访问限制。
这里的allow是指定了允许访问的ip地址,allow的值是正则表达式,明显默认值表示只能由本地访问,所以我使用nginx代理的时候访问是没有问题的。
因此这里只需将allow的值修改为符合条件的正则表达式,例如最简单的 allow="^.*$" 。当然,除非有特别的需要,最方便的做法还是直接注释了。
tomcat默认用户名密码修改
在CATALINA_HOME/conf/tomcat-users.xml文件中。编辑这个文件,可以修改用户名和密码,例如添加一个名为“manager”的角色到该文件中:
Tomcat8配置tomcat-users.xml配置
默认tomcat-user.xml中的角色和用户配置示例如下:
<!-- <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后访问http://localhost:8081/manager/html,会报403 Access Denied无法登录管理界面。
正确的配置如下:
<role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user username="admin" password="111111" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
但是tomcat8.5 更改之后,仍然访问拒绝。
还需步骤如下:
/apache-tomcat-8.5.9/webapps/manager/META-INF/context.xml
原因是tomcat8中定义了以下4种角色,所以配置文件中的角色名称是不能任意填写的。
manager-gui - allows access to the HTML GUI and the status pages
manager-script - allows access to the text interface and the status pages
manager-jmx - allows access to the JMX proxy and the status pages
manager-status - allows access to the status pages only