The local configuration of the Linux system starts two tomcats and realizes simple nginx load balancing

overview

Deploy two tomcats on a Linux system, and use nginx to achieve simple load balancing
Related links:
Linux system nginx installation detailed steps
Linux installation and configuration jdk
Linux deployment of dual tomcat
The above link is about installing and configuring nginx, jdk, and dual tomcats on a Linux system related links

This article only writes in detail to modify the relevant configuration on nginx to achieve the purpose of load balancing between two tomcats

nginx related configuration

The author has deployed tomcat with port numbers 8080 and 8081 in his own Linux environment. The weight behind means weight. The higher the weight ratio, the higher the possibility that nginx will proxy to the corresponding URL.
insert image description here
After the configuration is complete, remember to reload the nginx service in the sbin directory of nginx./nginx -s reload.

Experiment and result verification

Open the server with port 8080 of tomcat, access port 9880 of nginx, and the proxy tomcat URL appears.
insert image description here
Only open 8080 of tomcat and close 8081. Let's see how the nginx log is written
insert image description here
access.log shows successful access on 4/10
insert image description here

The error.log shows that the access to port 8081 failed on 4/10.

So far we have successfully achieved load balancing of accessing nginx to dual tomcat.

Why the access to port 8081 fails, but the webpage can still be displayed correctly?
This is because when the nginx server finds that the access to the 8081 page fails, it will immediately switch to the 8080 service port.

Guess you like

Origin blog.csdn.net/adaizzz/article/details/130053664