Master Nginx: Basics, Reverse Proxy, Load Balancing & High Availability
This comprehensive guide explains Nginx fundamentals, reverse‑proxy and load‑balancing concepts, static‑dynamic separation, Linux installation, configuration file structure, practical reverse‑proxy and load‑balancing examples, and high‑availability setup using Keepalived.
What is Nginx?
Nginx is a high‑performance HTTP server and reverse proxy that uses little memory and can handle tens of thousands of concurrent connections.
Key Features
Designed for performance, Nginx can support up to 50 000 concurrent connections.
Architecture Overview
Nginx knowledge‑map structure:
Proxy Types
Forward proxy: LAN clients must access the Internet through a proxy server.
Reverse proxy: Clients send requests to the reverse‑proxy server, which forwards them to backend servers and returns the response, hiding the real server IP.
Load Balancing
Distribute client requests across multiple backend servers to improve scalability. Example: 15 requests are split evenly among three servers (5 each).
Static‑Dynamic Separation
Serve static files with Nginx and dynamic content with Tomcat to accelerate page rendering.
Installation on Linux
Typical commands to manage Nginx:
./nginx -v ./nginx ./nginx -s stop ./nginx -s quit ./nginx -s reloadConfiguration File Structure
The nginx.conf consists of three blocks:
global – settings that affect the whole server.
events – network connection handling.
http – reverse proxy, load balancing, etc.
Example location directive syntax:
location [ = | ~ | ~* | ^~ ] url { # configuration }Reverse Proxy Practical Example
Configure Nginx to forward www.123.com (or 192.168.25.132:9001/edu/) to Tomcat instances on ports 8080 and 8081 using regular expressions.
Load Balancing Practical Example
Modify nginx.conf to define an upstream group and reload Nginx.
Supported algorithms: round‑robin (default), weight, fair, ip_hash.
High‑Availability with Keepalived
Install Keepalived, configure a virtual IP, and set up health‑check scripts so that if the primary Nginx fails, the backup takes over.
# yum install keepalived -y # systemctl start keepalived.serviceWorker‑Master Model
Nginx runs a master process that manages multiple worker processes; the number of workers should match the CPU core count for optimal performance.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
