Nginx
π§ Nginx
[!info] Nginx is a high-performance open-source web server, reverse proxy, and application server.
It's widely used for serving static content, load balancing, SSL termination, and acting as a gateway to application services.
π Project Homepage: Nginx Homepage
π Documentation: Nginx Unit Docs
π Overview
Type: Web Server / Reverse Proxy / Application Gateway
Purpose: Serve static content, reverse proxy dynamic apps, terminate SSL, balance load
Key Capabilities:
HTTP/2 and experimental HTTP/3 support
Custom logging, access control
Powerful location-based routing
SSL certificate management
π οΈ Features
π HTTP/HTTPS server with static file hosting
π Reverse proxy and load balancing
π Flexible configuration using
nginx.conf
π SSL termination and security headers
π§© Modular architecture for custom extensions
π οΈ FastCGI, SCGI, uWSGI, and gRPC support
π Getting Started
π§Ύ Basic Configuration
error_log logs/error.log;
error_log logs/debug.log debug;
listen 80;
listen 443 ssl http2;
listen 443 http3 reuseport; # experimental
server_name domain1.com *.domain1.com;
root /var/www/html/domain1;
index index.php;
[!tip] SSL Config
Nginx supports SSL out of the box β make sure to provide valid certificate and key files.
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
π§ Customization and Configuration
π§ Header Manipulation
add_header Alt-svc '$http3=":443"; ma=86400'; # experimental
π Location Blocks
location / {
root /var/www/html;
index index.html index.htm;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
[!warning] Always secure sensitive paths like
.ht
or backup files.
location ~ /\.ht {
deny all;
}
π Reverse Proxy
π Show Clientβs Real IP
server {
server_name example.com;
location / {
proxy_pass http://localhost:4000;
# Preserve client IP info
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[!tip]
Useproxy_set_header
for proper header forwarding when using Nginx as a reverse proxy behind load balancers or CDNs.
π Related
Let's Encrypt β Free SSL certificate provider
Docker β Frequently used with Nginx for containerized deployments
Nginx Config Examples β Handy tool to generate configs
π Explore More
π Tags
#Nginx
#WebServer
#ReverseProxy
#LoadBalancing
#SSL
#HTTP3
#FastCGI
#DevOps