A Load Balancer (LBR) is a critical infrastructure component that sits between clients and a cluster of backend servers. Its primary purpose is to distribute incoming network or application traffic efficiently across multiple servers.
graph TD
Client["Client Traffic (Internet)"] --> LBR["Nginx Load Balancer (stlbr01:80)"]
LBR --> App1["App Server 1 (stapp01:8087)"]
LBR --> App2["App Server 2 (stapp02:8087)"]
LBR --> App3["App Server 3 (stapp03:8087)"]
/api traffic to one pool and /static to another) and sticky sessions.NGINX is a high-performance web server, reverse proxy, load balancer, mail proxy, and HTTP cache. Unlike traditional thread-per-connection servers, Nginx uses an asynchronous, event-driven architecture, enabling it to handle tens of thousands of concurrent connections with a very low memory footprint.
As a Reverse Proxy, Nginx receives public incoming client requests and forwards them to internal upstream servers. It then intercepts the responses from the backend and returns them to the client.
Nginx supports several algorithms to distribute traffic:
least_conn): Directs new requests to the backend server with the lowest number of active connections. This is useful when requests take varying amounts of time to complete.ip_hash): Uses the client’s IP address to generate a hash key, mapping it to a specific backend server. This guarantees session persistence (sticky sessions), ensuring that a client always talks to the same backend server.weight=3). A server with higher weight receives a proportionally larger share of traffic (ideal for mixed-spec hardware).This guide details the steps to install Nginx on the Nautilus Load Balancer host, define backend upstream groups, and configure HTTP proxy passing.
stlbr01)lsa or designated sudo user)stapp01:8087stapp02:8087stapp03:808780 (public HTTP port)/etc/nginx/nginx.confSSH into the Load Balancer host from the Jump Host:
ssh lsa@stlbr01
Install the Nginx web server on the Load Balancer server:
sudo yum install -y epel-release
sudo yum install -y nginx
Open the main Nginx configuration file:
sudo vi /etc/nginx/nginx.conf
Locate the http context block. Add an upstream block to define your group of backend servers, and modify the default server block to proxy traffic to this group:
http {
# 1. Define the upstream backend group
upstream backend_servers {
server stapp01:8087;
server stapp02:8087;
server stapp03:8087;
}
# ... existing configuration parameters ...
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# 2. Redirect root traffic to the upstream group
location / {
proxy_pass http://backend_servers;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ... existing error configurations ...
}
}
Save and exit the file (in vi, press Esc, type :wq, and press Enter).
sudo nginx -t
Expected output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl enable --now nginx
sudo systemctl status nginx
From the Jump Host, run multiple curl commands to query the Load Balancer IP (or hostname stlbr01) and verify that it returns content successfully:
curl http://stlbr01
If the backend application servers display different index markers (e.g., printing their server names in the HTML body), running the query sequentially should output responses from stapp01, stapp02, and stapp03 in a round-robin rotation, indicating load distribution is functioning correctly.
Log out of the Load Balancer Server:
exit