Multi-application Deployment

1 – the tomcat configuration

1.1- Project Configuration

First go to the Tomcat directory and make a copy of the Webapps folder for the deployment of the second application.

cp webapps webapps1
Copy the code

At this point, you can upload the package under the webApps1 file for the second project you want to deploy as you would for a normal project.

1.2- Service Configuration

Go to the Tomcat service configuration file, open the server. XML configuration file, and fill in the configuration information for the second application deployment.

cd conf
vim server.xml
Copy the code

At the end of the file, add a service resolution configuration within.

  <! -- Second project configuration -->
  <Service name="Catalina1">
      
    <! -- To avoid conflicts, modify port -->
    <Connector port="81" protocol="HTTP / 1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
  
    <! -- Tomcat uses port 8009 by default to avoid conflicts.
    <Connector port="8010" protocol="AJP / 1.3" redirectPort="8443"/>
  	
    <!-- Engine 节点, name 修改为 Catalina1 -->
    <! The engine folder will be generated in conf after the service is started. The name of the engine folder will be the same.
    <Engine name="Catalina1" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
  
      <! AppBase = webApps1; 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>
Copy the code

2 – Nginx configuration

First go to the Nginx service directory conf configuration file, find the nginx.conf configuration file, edit.

vim nginx.conf
Copy the code

Add the reverse proxy configuration information inside HTTP {}.

(1) : nginx will load "website{server localhost" : (1) : nginx will load "server localhost" :81;
                server localhost:82;
        }

        server{
                listen 80; # configure the domain name to be resolved, and ensure that this domain name is accessible to the current server server_name WWW123..com; Location / {# place the above defined object below to proxy 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; }}Copy the code

3- Complete the deployment

After completing the above two steps, restart Tomcat and Nginx, and the two applications can be accessed separately by domain name.

Go to the bin directory and restart tomcat. /shutdown.sh./startup.shCopy the code
Reload nginx./nginx -s reloadCopy the code