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]
Use proxy_set_header for proper header forwarding when using Nginx as a reverse proxy behind load balancers or CDNs.


  • 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