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

Introduction to installing and configuring JDK under CentOS system

Table of contents Preface Check and uninstall Ope...

Native JS to implement click number game

Native JS implements the click number game for yo...

How to modify the user and group of a file in Linux

In Linux, when a file is created, the owner of th...

N ways to cleverly implement adaptive dividers with CSS

Dividing lines are a common type of design on web...

CSS style to center the HTML tag in the browser

CSS style: Copy code The code is as follows: <s...

Nginx configuration SSL and WSS steps introduction

Table of contents Preface 1. Nginx installation 1...

Analysis of Mysql data migration methods and tools

This article mainly introduces the analysis of My...

MySQL subqueries and grouped queries

Table of contents Overview Subqueries Subquery Cl...

How to solve the front-end cross-domain problem using Nginx proxy

Preface Nginx (pronounced "engine X") i...

Introduction to JavaScript conditional access attributes and arrow functions

Table of contents 1. Conditional access attribute...

How to use rem adaptation in Vue

1. Development environment vue 2. Computer system...

Analysis of CocosCreator's new resource management system

Table of contents 1. Resources and Construction 1...

MySQL export of entire or single table data

Export a single table mysqldump -u user -p dbname...

How to open ports to the outside world in Alibaba Cloud Centos7.X

In a word: if you buy a cloud server from any maj...