Tomcat using Nginx for load balancing is a simple thing
1. Environment preparation
The two machine IPs are 192.168.0.166 192.168.0.167 , respectively.
of which 166 installed Nginx
166 and 167 to install Tomcat separately
Of course, you can choose another machine to install nginx because I don't have that machine, so I installed Nginx in 166.
2. Configuration files
The basic configuration of Nginx is described in the previous article, which only needs to be configured with the following two sections on the basic configuration.
#使用域名 www.test.com(可以自己随便定义,也可以使用IP地址)
upstream www.test.com {
#server is the two tomcat ports that you want to achieve load balancing by default, 8080,IP is 166 and 167.
server 192.168.0.166:8080;
server 192.168.0.167:8080;
}
Server {
listen 80;
server_name www.test.com;
#charset koi8-r;
#其中~^/rzdb 是一个正则表达式,意思是只要访问的地址中出现rzdb(也就是我的项目名字)
location ~^/rzdb {
proxy_pass http://www.test.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Configuration complete, start Nginx.
Access to http://www.test.com/rzdb/index.html access successfully;
The above describes the Nginx tomcat to achieve load balancing, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.