1. install necessary software
Server Load balancer: set IP address to 192.168.1.10
Web Server 1: install Apache or nginx and set the IP address to 192.168.1.11;
Web Server 2: install Apache or nginx and set the IP address to 192.168.1.12.
Ii. Configure the server Load balancer instance
1. Create an extra folder under the nginx conf directory and edit and generate a configuration file, such as t_servers.conf.
Upstream test_servers {
Server 192.168.1.11: 80 Weight = 5;
Server 192.168.1.12: 80 Weight = 5;
}
Server {
Listen 80;
SERVER_NAME 192.168.1.10;
Location /{
Proxy_pass http: // test_servers;
}
}
2. Edit the nginx. conf file under the nginx conf directory, and only keep the necessary configurations below, and save the configuration files under the last line include.
Worker_processes 1;
Events {
Worker_connections 1024;
}
HTTP {
Include mime. types;
Default_type application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Include extra/t_servers.conf;
}
3. Restart the nginx Server
Each access to 192.168.1.10 will automatically switch between Web Server 1 and Server 2 to achieve load balancing and reverse proxy. If one of the Web servers goes down, the access will automatically jump to the working web server. If nginx is down, error 502 is returned.