Nginx is a lightweight Web/reverse proxy server and E-mail (IMAP/POP3) proxy server distributed under a BSD-like protocol. It is characterized by less memory and strong concurrency.

First: to do some preparation, at least two Tomcat, set up two other domain names and resolve to local IP (because nginx is directly configured domain name)

(1) Prepare two Tomcats

Set the port numbers in tomcat /conf/server. XML as follows

Tomcat1 Set port numbers to 8205 8280 8209

Set tomcat2 port numbers to 8215 8281 8219

(2) Add test content

Delete all files in the webapps directory, create a folder ROOT, and create index.html in this directory

The content can be set to: here is port 8280. (Another: This is port 8281.)

(3) Start both Tomcat

(4) Visit two Projects under Tomcat respectively

Visit the following two sites:

127.0.0.1/8280

127.0.0.1/8281

If you can access the corresponding index.html file, Tomcat is configured and started successfully.

(5) Set two domain names and resolve them

Modify the hosts file to set up two domain names, tomcat1.com and tomcat2.com, and resolve to local IP: 127.0.0.1

Path: C: \ Windows \ System32 \ drivers \ etc

Open the hosts file and add (If the modification cannot be saved, copy the hosts file to the desktop and replace the original hosts file after modification).

Add the following:

127.0.0.1 tomcat1.com

127.0.0.1 tomcat2.com

(6) Check whether the domain name is successfully resolved

127.0.0.1/8280; 127.0.0.1/8281 is changed to 127.0.0.1/8281

Tomcat1.com: 8280; tomcat2.com:8281

If information similar to the preceding figure is displayed, the domain name is successfully resolved.

Configure the direction proxy for the Nginx server.

1. Download and install the Nginx server

Enter the url: nginx.org/en/download… , choose a suitable version, download and decompress to the appropriate path.

After decompression, as shown: nginx.exe can be run directly, but it is not recommended.

2. Configure the reverse proxy

Open /conf/nainx.conf and delete the server{…… }, or log off

Re-add server{}

Listen: indicates the listening port number

Server_name: Access domain name

Location: this is configured as/directly matches the project under the default ROOT port.

See also: segmentfault.com/a/119000000…

Proxy_pass: indicates the actual access address of the project

server {
        listen       80; 
        server_name  tomcat1.com;
        #charset koi8-r;
        #access_log logs/host.access.log main;Location / {proxy_pass http://127.0.0.1:8280; index index.html index.htm; } } server { listen 80; server_name tomcat2.com;#charset koi8-r;
        #access_log logs/host.access.log main;Location / {proxy_pass http://127.0.0.1:8281; index index.html index.htm; }}Copy the code

3. Start, close, and restart the Nginx server

Open cmd.exe to run the command.

Note: Be sure to operate in the same folder as the nginx.exe file.

(1) Start:

H: \ nginx 1.12.2 – > start nginx

Or the H: \ nginx – 1.12.2 > nginx. Exe

Note: It is recommended to use the first option, the second option will keep your CMD window in execution and cannot perform other command operations.

(2) Stop:

H: \ nginx – 1.12.2 > nginx. Exe – s stop

Or the H: \ nginx – 1.12.2 > nginx. Exe – s quit

Note: stop is to stop nginx quickly, and may not save related information; Quit is a complete and orderly stop to nginx and save the information.

(3) Reload Nginx:

H: \ nginx – 1.12.2 > nginx. Exe – s reload

This command is used when the configuration information is modified and needs to be reloaded.

(4) Reopen the log file:

H: \ nginx – 1.12.2 > nginx. Exe -s reopen

4. Check whether the configuration is successful

Enter the domain names: tomcat1.com and tomcat2.com

If the following information is displayed after you enter the domain name, the configuration is successful.

5. Possible problems (process shutdown failure)

You may run into a strange problem when using the close command several times, but the page is still accessible by domain name.

If your process is not shut down, you can use the following command to check:

CMD type: netstat – an | find 0:8 “0”

If so, the process is not closed. No, let’s see if it’s browser caching.