Tomcat配置
# 03.Tomcat配置
接下来我们来讲讲简单的配置Tomcat。
# Tomcat后台管理
默认情况下,我们安装Tomcat之后,访问Tomcat主页面,出现如下图所示界面:
当我们需要访问Manager App或者Host Manager时:

提示需要密码:

不输入会提示出现如下所示的错误:401

# 增加用户
401表示无权限。根据提示,我们需要在Tomcat安装目录下的conf/tomcat-users.xml配置文件中增加用户角色和用户。
另外,还需要修改webapps/manager/META-INF/context.xml配置文件,修改访问地址的限制。
一、增加用户角色和用户:conf/tomcat-users.xml,我们在<tomcat-users>
标签体里增加如下角色和一个admin用户:
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<user username="admin" password="123456" roles="admin-gui,manager-gui,manager-jmx,
manager-script,manager-status"/>
2
3
4
5
6
7
二、修改地址访问限制:webapps/manager/META-INF/context.xml
更改之前的设置,只容许本机访问:第22行里配置了只允许本机访问127.0.0.1
<?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.
-->
<Context antiResourceLocking="false" privileged="true" >
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<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"/>
</Context>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
更改为:
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="^.*$" />
</Context>
2
3
4
更改配置之后,重启Tomcat,访问Manager App和Host Manager就没有问题了
Manager App:
Host Manager:
# server.xml其他配置
server.xml 文件当中可配置如下信息:
配置端口号:大概69行处
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
2
3
4
配置域名:修改 localhost标签里的name属性(151行处左右)
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
2