Last Updated: November 21, 2025
Basic Commands
nginx -t
Test configuration
nginx -s reload
Reload configuration
nginx -s stop
Stop server
nginx -s quit
Graceful shutdown
systemctl start nginx
Start nginx (systemd)
systemctl status nginx
Check status
Basic Server Block
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
# Static files caching
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
}
}
Reverse Proxy
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
SSL/HTTPS
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# Redirect HTTP to HTTPS
}
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
💡 Pro Tip:
Always test config with nginx -t before reloading!