: This article mainly introduces how to use nginx to enable load balancing for multiple tomcat servers. For more information about PHP tutorials, see. Because the project has been officially deployed and released in the directory, but bugs may occur from time to time. after the bug is fixed and submitted again, the project may be inaccessible for a short time, although the time is short, it will still affect the user experience. In order not to let the user notice the changes, I used nginx to achieve load balancing. The main steps are as follows:
1. configure the nginx installation source
Vim/etc/yum. repos. d/nginx. repo
# Nginx. repo
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
2. install nginx
If nginx has been installed, you need to upgrade it and execute update.
Yum update nginx
If not installed, run the following command to install
Yum install nginx-y
Nginx-v // view the version
3. view the nginx installation directory
Whereis nginx
4. edit the nginx configuration file
Cd/etc/nginx
Vim nginx. conf
Here, the nginx. conf source code is attached:
user nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf;}As shown above, the/etc/nginx. conf. d/*. conf file is also called.
Add the default. conf source code:
upstream school {server 192.168.1.103:80;server 192.168.1.100:8080;server 192.168.1.101:80;}server { listen 80; server_name school; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { # root /usr/share/nginx/html;proxy_pass http://school; # index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }}In this way, the simple load of the three servers is completed.
5. check whether the nginx configuration is correct.
Nginx-t
"OK" and "successful" are displayed, indicating that the configuration is correct.
6. start nginx
Start nginx.
Service nginx start
Enter the nginx address to test the function:
From this we can see that the tomcat service is different for each execution. OK! SUCCESS !!!
The above section describes how to use nginx to achieve load balancing for multiple tomcat servers, including some content. I hope to help some friends who are interested in PHP tutorials.