Tomcat【环境搭建 02】Web端403 Access Denied You are not authorized to view this page解决方法(Tomcat 10.2.12 版本)
1. 問題說明
啟動Tomcat之后,我們常常是要打開Web端進行驗證,其實Web端的功還有很多,但是有一些管理頁面權限不足:
我們點擊 Manager Status 或 Manager App 鏈接之后會報錯 403 Access Denied You are not authorized to view this page :
而點擊 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.xmlcontext.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在<tomcat-users></tomcat-users>標簽內添加以下信息:
<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 頁面需要再次進行登錄(密碼相同)可以管理虛擬主機:
至此,全部的 Web端 403 Access Denied 問題解決~
總結
以上是生活随笔為你收集整理的Tomcat【环境搭建 02】Web端403 Access Denied You are not authorized to view this page解决方法(Tomcat 10.2.12 版本)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Tomcat【环境搭建 01】安装包版本
- 下一篇: 【Java报错】java.lang.Cl