Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Server \ CentOS Nginx achieve 3 virtual machine load balancing     - GDB remote connections RX Probe online debug program (Programming)

- Linux / Centos anti CC attack script (Linux)

- Linux shell scripts bubble sort (Programming)

- Ubuntu install code editor Sublime Text 3 (Linux)

- RHEL7 system making use of OpenStack mirror (Linux)

- Linux user login and IP restrictions (Linux)

- Github with .gitignore ignore specified file (Linux)

- Java filter (Programming)

- RHEL / CentOS / Fedora Install Nagios 4.0.1 (Linux)

- To assign multiple IP addresses NIC on the CentOS 7 (Linux)

- How to disable UEFI to install Linux on Win8 (Linux)

- Configuring automatic mail GAMIT under CentOS system (Linux)

- Android Studio commonly used shortcuts and how to follow the Eclipse Shortcuts (Linux)

- Compile Android libwebcore.so error occurs when solving (Programming)

- How to manage start-up applications in Ubuntu (Linux)

- High-performance open-source http accelerator Varnish introduce (Server)

- Ubuntu installed Gimp 2.6.11 (stable version) with PPA (Linux)

- PostgreSQL using the system cache to improve operational efficiency (Database)

- Hadoop 2.0 Detailed Configuration Tutorial (Server)

- Free compiler install MySQL-5.6.14 (Database)

  CentOS Nginx achieve 3 virtual machine load balancing
  Add Date : 2018-11-21      
  Load Balancing

First take a brief look at what is load balancing, just from the literal meaning can be interpreted to understand the average N servers share the load, the situation will not be a high server load down a server while idle. So the premise is to load balancing multiple servers can be achieved, that is, two or more.

test environment
In VMware was installed three CentOS.

A server IP: (Main)

B Server IP:

C Server IP:

Deployment Ideas
A server to do the main server, the domain name resolves to direct the A server (, from A to B server load balancing server ( and C server ( on.

On A server, upstream command - load distribution

vi /etc/nginx/conf.d/default.conf


upstream {

server {
    listen 80;
    charset utf8;
    location / {
        proxy_set_header Host $ host;
        proxy_set_header X-Real-IP $ remote_addr;
        proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;

Save restart nginx


In the B, C servers,

vi /etc/nginx/conf.d/default.conf


server {
    listen 80;
    index index.html;
    root / usr / share / nginx / html;


Save restart nginx

When access, in order to distinguish which server process is turning me were written in a different content of B, C server index.html file to distinguish.

Open a browser to access a.com result, the refresh will find all of the requests are respectively the primary server ( assigned to the B server ( and C server ( on the realization of load balancing effect.

Master server can not provide services?
The above example, we are all applied to the primary server load balancing to other servers, the primary server itself can also add in the server list, so you do not waste a single server to get as pure forwarding function, but is also involved in to provide services in the past.

How to solve this problem? 80 because the port is already used to monitor the load balancing process, so on this server can not use port 80 to handle access requests, and starting a new one.

So we edit /etc/nginx/conf.d/default.conf the primary server, add the following

server {
    listen 8080;
    index index.html;
    root / usr / share / nginx / html;

Restart nginx

Then, re-crossing the load balancing.
- Linux non-root user uses less than 1024 ports (Linux)
- SSH without password Definitive Guide (Linux)
- Database start listening TNS-12537, TNS-12560 error (Database)
- Ubuntu and derivative users to install the system launcher SimDock 1.3 (Linux)
- Oracle how to maintain the consistency of read? (Database)
- GitLab issued Merge Request return error 500 when the two solutions log (Linux)
- Android source code compiled fatal error solutions (Programming)
- Apache site default home page settings (Server)
- Oracle GoldenGate encryption (Database)
- Install VLC player on Ubuntu 14.10 (Linux)
- IP Security Policy is to learn how to prevent Ping and closed ports (Linux)
- Kubernetes (k8s) environment to build combat (Server)
- MySQL dual master configuration (Database)
- Android Studio and Git Git configuration file status (Linux)
- Linux, security encryption to transfer files between machines (Linux)
- Use MD5 transform algorithm to prevent exhaustive decipher passwords (Linux)
- Linux Thread Synchronization (Programming)
- Ubuntu under Spark development environment to build (Server)
- Command-line based tools for better alternatives (Linux)
- Basic Tutorial: Linux novice should know 26 commands (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.