advanced tomcat

1. tomcat

1. Multi-domain access test

Change the <Host> of the server.xml file, and each domain name or IP is a separate <Host></Host> tag.

The core is the name parameter and appBase parameter. Name fills in the domain name, name is localhost, which means it can be accessed through the public network IP, and appBase fills in the directory path. Note that there must be a ROOT directory under the directory path, and the project is placed in the ROOT directory.

When using a domain name or IP to access, if there is no directory behind the url, then jump directly to the ROOT directory.

Pay attention to change the default port 8080 to port 80.

DNS resolution, add A record, A record can point the domain name to IP

Test index.html under ROOT

index.html under images

!!!Notice

Suppose your site domain name is www.abc.top, and you add a third-level domain name www.test1.abc.top in DNS resolution, and set name="www.abc. top", then what will the screen be accessed by the user using the third-level domain name www.test1.abc.top?

test

www.abc.top access to test01

I used www.test1.abc.top to access the tomcat homepage, but I did not set the third-level domain name in server.xml. It can be seen that, in essence, the third-level domain name is directly forwarded to the IP instead of the second-level domain name.

www.test1.abc.top is not set in the tomcat configuration file, but DNS resolves to www.test1.abc.top resolves to the IP of the domain name, and directly accesses port 80 of the IP, which is the home page of tomcat.

2. Multi-port access test

Add a pair of <Service></Service> in server.xml, pay attention to change the port.

3. tomcat-manager monitoring

tomcat-manager is the monitoring system that comes with tomcat, change ~/conf/tomcat-user.xml

  <role rolename="manager-script"/>
  <role rolename="manager-gui"/>
  <role rolename="manager-jmx"/>
  <user username="tomcat" password="tomcat" roles="manager-script,manager-gui,manager-jmx"/>
  <user username="both" password="123456" roles="tomcat,role1"/>
  <user username="role1" password="123456" roles="role1"/>

在tomcat服务器的conf/Catalina/localhost/目录下创建一个manager.xml文件

<Context privileged="true" antiResourceLocking="false" docBase="${catalina.home}/webapps/manager">
    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

webapps下是否有manager,如果没有,从别的tomcat中复制一个。

测试,浏览器输入http://IP:port/managers/status,弹出登录页面,用户名是tomcat,密码是tomcat如果显示403报错,需要~//webapps/manager/META_INF/context.xml去除对访问权限的设置,重启tomcat。

<Context antiResourceLocking="false" privileged="true" >
  <!--注释这里,去除对访问权限的设置
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
         -->
</Context>

Guess you like

Origin blog.csdn.net/weixin_48878440/article/details/129337888