java---tomcat multi-application deployment

Multi-application deployment

1-tomcat configuration

 1.1-Project configuration

 First enter tomcatthe directory of , and webappsmake a copy of the folder in it for the deployment of the second application.

cp webapps webapps1
复制代码

1.png

 At this point, you can upload the data package to the webapps1file .

 1.2-Service configuration

 Go to tomcatthe service configuration file of , open the server.xmlconfiguration file, and fill in the relevant configuration information when the second application is deployed.

cd conf
vim server.xml
复制代码

2.png

 At the end of the file,add aService resolution configuration.

  <!-- 第二个项目配置 -->
  <Service name="Catalina1">
      
    <!-- 为避免冲突, 修改端口 -->
    <Connector port="81" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
  
    <!-- Tomcat默认使用8009端口, 避免冲突, 修改 -->
    <Connector port="8010" protocol="AJP/1.3" redirectPort="8443"/>
  	
    <!-- Engine 节点, name 修改为 Catalina1 -->
    <!-- 服务启动后会在 conf 下生成相应的引擎文件夹, 名称保持一致. -->
    <Engine name="Catalina1" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
  
      <!-- 修改Host节点,appBase修改为需要进行发布的文件位置, 也就是第一步复制的 webapps1 -->
      <Host name="localhost"  appBase="webapps1"
            unpackWARs="true" autoDeploy="true">
  
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  
      </Host>
    </Engine>
  </Service>
复制代码

2-Nginx configuration

 First go to the configuration file Nginxin the service directory of conf, find the nginx.confconfiguration file, and edit it.

vim nginx.conf
复制代码

3.png

http{}Add the  relevant configuration information of the reverse proxy inside the .

# website 随便取, 只是进行一个标识, 里面的就是相应的需要进行代理的 ip : port
# 多个服务也可以直接填入, nginx会自动进行负载
upstream website{
                server localhost:81;
                server localhost:82;
        }

        server{
                listen 80;
                # 配置需要进行解析的域名信息, 确保这个域名是可以访问到当前的服务器的
                server_name  www.123.com;
                location / {
                		# 将上面定义对象放在下面进行代理
                        proxy_pass http://website;
                        proxy_set_header Host $http_host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                }
        }
复制代码

3- Complete the deployment

 After the above two steps are completed tomcat, Nginxrestart, and the two applications can be accessed through the domain name alone.

# 进入到 bin 目录下重启 tomcat
./shutdown.sh
./startup.sh
复制代码
# 进入到 sbin 目录下重启 nginx
./nginx -s reload
复制代码

Guess you like

Origin juejin.im/post/7083850328814141470