Tomcat【部署 02】Web端403 Access Denied You are not authorized to view this page解决方法(Tomcat 10

在这里插入图片描述
而点击 Host Manager 链接之后报错信息不同:

在这里插入图片描述

2. 问题解决
2.1 修改配置文件

403页面提到的第 1️⃣ 个文件:默认情况下,只能从运行在与 Tomcat 相同机器上的浏览器访问Manager。如果您希望修改此限制,则需要编辑 Manage r的 context.xml 文件。查看以下:

<!-- The contents of this file will be loaded for each web application -->
<Context>
    <!-- Default set of monitored resources. If one of these changes, the -->
    <!-- web application will be reloaded. -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
    <!-- Uncomment this to enable session persistence across Tomcat restarts -->
    <!--
 <Manager pathname="SESSIONS.ser" />
 -->
</Context>

vim /usr/local/tomcat/conf/context.xml

context.xml里有两方面的描述,一个是检测资源的配置(文件修改则会重新加载),另一个是session会话的使用。似乎没有权限相关的说明,我们取消第二部分的注释以便在Tomcat重启后保持会话。

403页面提到的第 2️⃣ 个文件: conf/tomcat-users.xml That file must contain the credentials to let you use this webapp. 该文件必须包含允许您使用此webapp的凭据。【满满的角色权限相关的说明】 我们按照举例修改 tomcat-users.xml 文件添加角色和用户:

vim /usr/local/tomcat/conf/tomcat-users.xml

在标签内添加以下信息:

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

❗️❗️❗️ 注意: 重启 Tomcat 后再次访问 Manager Status 或 Manager App 页面,不出意外的话还是会报 403 Access Denied 错误的,为什么呢?我们再认真看看报错信息:

  • 访问 Manager Status 或 Manager App 页面时的报错信息:

If you wish to modify this restriction, you’ll need to edit the Manager's context.xml file.

  • 访问 Host Manager 页面时的报错信息:

If you wish to modify this restriction, you’ll need to edit the Host Manager's context.xml file.

此时才明白403页面说的 context.xml 并非 $CATALINA_HOME/conf/ 下的 context.xml 文件,而是 $CATALINA_HOME/webapps/manager/META-INF/context.xml$CATALINA_HOME/webapps/host-manager/META-INF/context.xml 这两个文件,全部修改 RemoteAddrValve 的值:

<!-- RemoteAddrValve的原始值 -->
 <Valve className="org.apache.catalina.valves.RemoteAddrValve" 
 allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
 <!-- RemoteAddrValve修改后的值(其实就是释放所有IP的访问权限) -->
 <Valve className="org.apache.catalina.valves.RemoteAddrValve" 
allow="\d+\.\d+\.\d+\.\d+" />

2.2 重启登录

重新启动后,点击 Server Status 或 Manager App 页面,需要登录,此时输入 tomcat-users.xml 文件设置的用户及密码:

在这里插入图片描述
登录成功后 Server Status 可以查看服务器状态:

在这里插入图片描述

Manager App 可以在Web页面上部署项目:

在这里插入图片描述

而 Host Manager 页面需要再次进行登录(密码相同)可以管理虚拟主机:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值