Target: Nginx as Httpserver, connect multiple Tomcat application instances, load balance.
Note: This example takes a machine as an example, that is, the same machine is loaded with an nginx and 2 tomcat and installed JDK1.7.
1. Installing Nginx
Installing Nginx Tutorials
2. Configure two Tomcat
Configure two tomcat on this machine, tomcat7-8081, tomcat7-8082, respectively.
tomcat7-8081 Access Address: http://localhost:8081, browse display content: This is 8081 port
tomcat7-8082 Access Address: http://localhost:8082, browse display content: This is 8082 port
The contents of the D:\div\tomcat7-8081\webapps\ROOT\index.jsp file are:
<! DOCTYPE HTML > < lang= "en"> <head>This is 8081 Port</head></html>
The contents of the D:\div\tomcat7-8082\webapps\ROOT\index.jsp file are:
<! DOCTYPE HTML > < lang= "en"> <head>This is 8082 Port</head></html>
Configure multiple Tomcat tutorials on the same server
So we successfully built a Nginx service, successfully configured two Tomcat application instances.
3. Nginx+tomcat Load Balancing Configuration
Only the Nginx configuration needs to be modified so that it can be forwarded via Tomcat.
A, nginx.conf configuration file
Worker_processes 1; events { worker_connections ;} HTTP { include mime.types; Default_type application/octet-stream; Sendfile on ; Keepalive_timeout ; Include extra/upstream01.conf;}
b, extra/upstream01.conf file, load balancer configuration information
upstream MySite { server localhost:8081 weight=5; Server localhost:8082 weight=5;} server { ; server_name localhost; / { proxy_pass http://MySite; }}
When a request is sent to localhost, the request is distributed to the list of servers for the corresponding upstream settings, and every server requested for distribution is random.
Then when you run the start Nginx, when you constantly refresh the http://localhost, the browser will switch back and forth "This is 8081 port" and "This is 8082 port".
This indicates that the load Balancer configuration was successful!!!!!!
Nginx + Tomcat Configuration Load Balancer