| name | nginx |
| description | Nginx web server configuration for reverse proxy, SSL/TLS, load balancing, static hosting, caching, and security hardening. Use when user asks to "configure nginx", "set up reverse proxy", "add SSL", "nginx location block", "load balancer config", "serve static files", "nginx rate limiting", "nginx caching", "nginx security headers", "nginx gzip", "nginx docker", "fix 502 bad gateway", "fix 413 entity too large", "nginx rewrite", "nginx redirect", "nginx access control", "nginx logging", "nginx performance tuning", or any web server configuration tasks. |
Nginx
Web server configuration, reverse proxy, SSL/TLS, load balancing, caching, and security.
Configuration Structure
# /etc/nginx/nginx.conf — contexts nest: main → events/http → server → location
main context # worker_processes, error_log, pid
├── events { } # worker_connections, multi_accept
├── http { } # upstream, server, mime types, logging
│ ├── server { } # listen, server_name, ssl
│ │ └── location { } # request routing
│ └── upstream { } # backend pools
└── stream { } # TCP/UDP proxying (mail, databases)
/etc/nginx/nginx.conf
/etc/nginx/sites-available/
/etc/nginx/sites-enabled/
/etc/nginx/conf.d/
/etc/nginx/snippets/
Basic Server Block
server {
listen 80;
server_name example.com www.example.com;
root /var/www/myapp;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Reverse Proxy
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
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;
}
# WebSocket upgrade
location /ws/ {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400s;
}
}