Comprehensive Nginx Tutorial: Installation, Reverse Proxy, Load Balancing, Static/Dynamic Separation, and High‑Availability Setup
This step‑by‑step guide explains how to install Nginx, configure it for reverse proxy and load balancing, separate static and dynamic content, and achieve high availability with keepalived, while also covering Nginx’s architecture, thread model, and key configuration directives.
This article provides a complete tutorial on Nginx, covering its overview, installation, configuration, and advanced usage scenarios.
Chapter 1 – Nginx Overview : Introduces Nginx as a high‑performance HTTP and reverse‑proxy server used by major Chinese sites such as Baidu, Tencent, and Alibaba.
Chapter 2 – Single‑Instance Installation : Shows how to prepare the environment, install dependencies, download the source, compile and install Nginx, and start the service.
# yum install -y gcc gcc-c++ make libtool wget pcre pcre-devel zlib zlib-devel openssl openssl-devel<br/># wget http://nginx.org/download/nginx-1.18.0.tar.gz<br/># tar -zxvf nginx-1.18.0.tar.gz<br/># cd nginx-1.18.0<br/># ./configure<br/># make && make install<br/># /usr/local/nginx/sbin/nginxChapter 3 – Reverse Proxy : Demonstrates configuring Nginx as a reverse proxy for Tomcat, including location directives, proxy_pass, and example host mappings.
# vi /usr/local/nginx/conf/nginx.conf<br/>location / { proxy_pass http://127.0.0.1:8080; }Chapter 4 – Load Balancing : Explains upstream blocks, different balancing algorithms (round‑robin, weight, ip_hash, fair), and shows how to test load distribution across multiple backend ports.
# upstream myserver { server 192.168.206.128:8080; server 192.168.206.128:8081; }<br/>location / { proxy_pass http://myserver; }Chapter 5 – Static/Dynamic Separation : Shows how to serve static files directly from Nginx while proxying dynamic requests to Tomcat, using a separate root directory for static assets.
Chapter 6 – High‑Availability Cluster : Details setting up a master‑slave Nginx cluster with keepalived, configuring virtual IP, health‑check scripts, and failover procedures.
# yum install -y keepalived<br/># vi /etc/keepalived/keepalived.conf ...Chapter 7 – Detailed Configuration : Reviews global, events, http, server, and location blocks, explaining key directives such as worker_processes, worker_connections, sendfile, gzip, and access logs.
Chapter 8 – Nginx Internals : Describes Nginx’s multi‑process model, worker contention, connection counting, and formulas for estimating maximum concurrent connections for static and proxy workloads.
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.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
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.
