100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Nginx Cheat Sheet

Nginx Cheat Sheet

Core Nginx configuration syntax for serving static files, reverse proxying, load balancing, and TLS termination.

2 PagesIntermediateFeb 15, 2026

Basic Server Block

Serve static content on a domain.

nginx
server {    listen 80;    server_name example.com www.example.com;    root /var/www/example.com;    index index.html;    location / {        try_files $uri $uri/ =404;    }}

Reverse Proxy

Forward requests to an upstream application server.

nginx
server {    listen 80;    server_name api.example.com;    location / {        proxy_pass http://127.0.0.1:3000;        proxy_set_header Host $host;        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header X-Forwarded-Proto $scheme;    }}

Load Balancing

Distribute traffic across multiple backend servers.

nginx
upstream backend {    least_conn;    server 10.0.0.1:3000;    server 10.0.0.2:3000;    server 10.0.0.3:3000 backup;}server {    listen 80;    location / {        proxy_pass http://backend;    }}

TLS / HTTPS

Terminate SSL and redirect HTTP to HTTPS.

nginx
server {    listen 443 ssl;    server_name example.com;    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;    ssl_protocols TLSv1.2 TLSv1.3;}server {    listen 80;    server_name example.com;    return 301 https://$host$request_uri;}

Operational Commands

Managing the nginx process and config.

  • nginx -t- Test configuration syntax without applying it
  • nginx -s reload- Reload configuration gracefully without dropping connections
  • nginx -s stop / quit- Stop immediately (stop) or gracefully after finishing requests (quit)
  • systemctl reload nginx- Preferred way to reload on systemd-managed hosts
  • error_log / access_log- Directives controlling log destinations and verbosity levels
  • gzip on- Enables response compression to reduce bandwidth
Pro Tip

Always run 'nginx -t' before reloading in production; a syntax error during 'reload' leaves the old worker processes running, which can mask the mistake until the next full restart.

Was this cheat sheet helpful?

Explore Topics

#Nginx#NginxCheatSheet#DevOps#Intermediate#BasicServerBlock#ReverseProxy#LoadBalancing#TLSHTTPS#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet