Sample code for implementing multi-application deployment using tomcat+nginx

Sample code for implementing multi-application deployment using tomcat+nginx

Multi-application deployment

1-tomcat configuration

1.1- Project Configuration

First, go to the tomcat directory and copy the webapps folder for the deployment of the second application.

cp webapps webapps1 

insert image description here

At this point, you can deploy the second project in the same way as deploying a normal project, and upload the data package to the webapps1 file.

1.2-Service Configuration

Go to the tomcat service configuration file, open the server.xml configuration file, and fill in the relevant configuration information for the second application deployment.

cd confvim server.xml

insert image description here

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

<!-- Second project configuration-->
<Service name="Catalina1">
    
  <!-- To avoid conflicts, change the port -->
  <Connector port="81" protocol="HTTP/1.1"
             connectionTimeout="20000"
             redirectPort="8443" />

  <!-- Tomcat uses port 8009 by default, to avoid conflicts, modify -->
  <Connector port="8010" protocol="AJP/1.3" redirectPort="8443"/>
	
  <!-- Engine node, name changed to Catalina1 -->
  <!-- After the service is started, the corresponding engine folder will be generated under conf, and the name will remain the same. -->
  <Engine name="Catalina1" defaultHost="localhost">
    <Realm className="org.apache.catalina.realm.LockOutRealm">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>
    </Realm>

    <!-- Modify the Host node and change appBase to the location of the file to be published, which is webapps1 copied in the first step -->
    <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 conf configuration file under the Nginx service directory, find the nginx.conf configuration file, and edit it.

vim nginx.conf 

insert image description here

Add the reverse proxy configuration information inside http{} .

# Website is just a random name, it is just an identification, and the corresponding ip:port that needs to be proxied is inside it.
# Multiple services can also be directly filled in, nginx will automatically load upstream website{
                server localhost:81;
                server localhost:82;
        }

        server{
                listen 80;
                # Configure the domain name information that needs to be resolved, and ensure that this domain name can access the current server's server_name www.123.com;
                location / {
                		#Put the above defined object below for 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 deployment

After completing the above two steps, restart tomcat and Nginx , and the two applications can be accessed separately through domain names.

# Enter the bin directory and restart tomcat
./shutdown.sh
./startup.sh
# Enter the sbin directory and restart nginx
./nginx -s reload

This concludes this article on sample code for implementing multi-application deployment with tomcat+nginx. For more information on multi-application deployment with tomcat+nginx, please search previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Summary of the deployment of Tomcat cluster and Nginx load balancing based on Docker
  • Nginx+Tomcat multi-site deployment method
  • Detailed explanation of how Nginx + Tomcat reverse proxy can efficiently deploy multiple sites on one server
  • Detailed Nginx + Tomcat reverse proxy load balancing cluster deployment guide

<<:  Detailed explanation of CSS3 animation and new features of HTML5

>>:  The functions and differences between disabled and readonly

Recommend

Vue commonly used high-order functions and comprehensive examples

1. Commonly used high-order functions of arrays S...

Detailed explanation of docker nginx container startup and mounting to local

First, the structure inside the nginx container: ...

Undo log in MySQL

Concept introduction: We know that the redo log i...

Summary of seven sorting algorithms implemented in JavaScript (recommended!)

Table of contents Preface Bubble Sort Basic Algor...

CSS3 custom scroll bar style::webkit-scrollbar sample code detailed explanation

The default scroll bar style in Windows is ugly, ...

Detailed steps for deploying Microsoft Sql Server with Docker

Table of contents 1 Background 2 Create a contain...

JavaScript to achieve accordion effect

This article shares the specific code for JavaScr...

Detailed explanation of the construction and use of Docker private warehouse

The image can be saved on hub.docker.com, but the...

Implementation of pushing Docker images to Docker Hub

After the image is built successfully, it can be ...

What you need to know about creating MySQL indexes

Table of contents Preface: 1. Create index method...

Common properties of frameset (dividing frames and windows)

A frame is a web page screen divided into several ...

WeChat applet to determine whether the mobile phone number is legal example code

Table of contents Scenario Effect Code Summarize ...

What are your principles for designing indexes? How to avoid index failure?

Table of contents Primary key index Create indexe...