从01开始 从01开始
首页
  • 计算机科学导论
  • 数字电路
  • 计算机组成原理

    • 计算机组成原理-北大网课
  • 操作系统
  • Linux
  • Docker
  • 计算机网络
  • 计算机常识
  • Git
  • JavaSE
  • Java高级
  • JavaEE

    • Ant
    • Maven
    • Log4j
    • Junit
    • JDBC
    • XML-JSON
  • JavaWeb

    • 服务器软件
    • Servlet
  • Spring
  • 主流框架

    • Redis
    • Mybatis
    • Lucene
    • Elasticsearch
    • RabbitMQ
    • MyCat
    • Lombok
  • SpringMVC
  • SpringBoot
  • 学习网课的心得
  • 输入法
  • 节假日TodoList
  • 其他
  • 关于本站
  • 网站日记
  • 友人帐
  • 如何搭建一个博客
GitHub (opens new window)

peterjxl

人生如逆旅,我亦是行人
首页
  • 计算机科学导论
  • 数字电路
  • 计算机组成原理

    • 计算机组成原理-北大网课
  • 操作系统
  • Linux
  • Docker
  • 计算机网络
  • 计算机常识
  • Git
  • JavaSE
  • Java高级
  • JavaEE

    • Ant
    • Maven
    • Log4j
    • Junit
    • JDBC
    • XML-JSON
  • JavaWeb

    • 服务器软件
    • Servlet
  • Spring
  • 主流框架

    • Redis
    • Mybatis
    • Lucene
    • Elasticsearch
    • RabbitMQ
    • MyCat
    • Lombok
  • SpringMVC
  • SpringBoot
  • 学习网课的心得
  • 输入法
  • 节假日TodoList
  • 其他
  • 关于本站
  • 网站日记
  • 友人帐
  • 如何搭建一个博客
GitHub (opens new window)
  • JavaSE

  • JavaSenior

  • JavaEE

  • JavaWeb

    • 服务器软件

      • 什么是服务器软件
      • Nginx介绍
      • Nginx的安装和启停
      • Nginx配置
      • Nginx配置反向代理
      • Nginx配置多个反向代理
      • Nginx配置负载均衡
      • Nginx配置动静分离
      • Nginx集群概念
      • Nginx配置高可用(主从)
      • Nginx原理
      • Nginx日志管理
      • Nginx手册
      • Nginx系列完结
      • Tomcat介绍
      • Tomcat安装和启停
      • Tomcat配置
        • Tomcat后台管理
        • 增加用户
        • server.xml其他配置
      • Tomcat部署项目
      • IDEA新建JavaWeb项目
      • Tomcat集群
      • 服务器软件
    • 环境管理和配置管理-科普篇
    • Servlet入门

    • JavaWeb
  • Spring

  • 主流框架

  • SpringMVC

  • SpringBoot

  • Java并发

  • Java源码

  • JVM

  • 韩顺平

  • Java
  • Java
  • JavaWeb
  • 服务器软件
2023-04-17
目录

Tomcat配置

# 03.Tomcat配置

接下来我们来讲讲简单的配置Tomcat。   ‍

# Tomcat后台管理

默认情况下,我们安装Tomcat之后,访问Tomcat主页面,出现如下图所示界面:

​​​​

‍

‍

当我们需要访问Manager App或者Host Manager时:

​![]​(https://image.peterjxl.com/blog/image-20211023214840-dklx1bx.png)​

‍

‍

提示需要密码:

​![]​(https://image.peterjxl.com/blog/image-20211023214800-g4tcc0b.png)​

‍

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

​![]​(https://image.peterjxl.com/blog/image-20211023214911-aty929q.png)​

‍

# 增加用户

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"/>
1
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>

1
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>
1
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" />
1
2
3
4

‍

‍

配置域名:修改 localhost标签里的name属性(151行处左右)

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
1
2

‍

在GitHub上编辑此页 (opens new window)
上次更新: 2023/5/16 08:48:08
Tomcat安装和启停
Tomcat部署项目

← Tomcat安装和启停 Tomcat部署项目→

Theme by Vdoing | Copyright © 2022-2023 粤ICP备2022067627号-1 粤公网安备 44011302003646号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式