Comprehensive Guide to Nginx: Installation, Configuration, and Advanced Features
This article provides a detailed, step‑by‑step tutorial on Nginx, covering its purpose, core features, installation on Linux, essential commands, configuration file structure, practical examples for static serving, reverse proxy, load balancing, HTTPS, security hardening, health checks, and load‑balancing algorithms.
Introduction : The author shares eight years of Nginx experience, presenting a concise yet thorough guide for front‑end developers and anyone interested in server‑side infrastructure.
What is Nginx? Nginx ( Nginx ) is a high‑performance HTTP and reverse‑proxy server written in C, created by Igor Sysoev in 2004 to handle massive traffic.
Reverse Proxy vs. Forward Proxy : Forward proxy hides the client, while reverse proxy hides backend servers, forwarding client requests based on configured rules.
Core Features of Nginx :
Event‑driven architecture using I/O multiplexing.
High scalability – thousands of concurrent connections.
Lightweight memory footprint compared to process‑based servers.
Hot deployment without restarting.
Built‑in load balancing via the upstream module.
High performance for static files and proxying.
SSL/TLS support for secure communications.
Installation on Linux:
sudo apt update
sudo apt install nginxor on Red Hat based systems:
sudo yum install epel-release
sudo yum install nginxStart and enable the service:
sudo systemctl start nginx
sudo systemctl enable nginxCommon Commands (Bash): start, stop, reload, test config, view version, check processes, view logs, etc.
Configuration File Structure :
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {}
error_page 500 502 503 504 /50x.html;
location = /50x.html {}
}
}Practical Configuration Examples :
Static resource serving with caching.
Reverse proxy to backend applications.
Load balancing using upstream and various algorithms.
HTTPS setup with certificates and strong ciphers.
Security hardening (header injection, request method filtering, rewrite rules).
Load Balancing Details :
Health checks (requires ngx_http_upstream_check_module ) and algorithms such as weight round‑robin (default), IP hash, fair (via extra module), and URL hash.
upstream backend {
server backend1.example.com weight=3;
server backend2.example.com;
server backend3.example.com weight=5;
}Example of health‑check configuration (requires third‑party module):
http {
upstream myapp1 {
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
check interval=10s fails=3 passes=2;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}
}Open‑Source Modules : Nginx has a rich ecosystem of modules; many are available on the NGINX community site or GitHub.
Conclusion : Even front‑end developers benefit from understanding Nginx basics, enabling them to configure, tune, and troubleshoot web servers when needed.
Rare Earth Juejin Tech Community
Juejin, a tech community that helps developers grow.
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.