Nginx Cheat Sheet
Nginx Common Quick Reference,
nginx |
Nginx |
nginx -s stop |
|
nginx -s quit |
|
nginx -s reload |
|
nginx -t |
Syntax |
nginx -V |
and Parameters |
systemctl enable nginx |
|
worker_processes auto; |
( CPU) |
worker_connections 1024; |
|
sendfile on; |
|
keepalive_timeout 65; |
|
server_tokens off; |
|
client_max_body_size 10m; |
|
Server
listen 80; |
80 |
listen 443 ssl http2; |
HTTPS + HTTP/2 |
server_name example.com; |
|
root /var/www/html; |
|
index index.html; |
Home |
return 301 https://...; |
|
Location
location / { } |
() |
location = / { } |
() |
location ^~ /static/ { } |
() |
location ~ \.php$ { } |
() |
location ~* \.(jpg|png)$ { } |
() |
try_files $uri $uri/ /index.html; |
SPA |
proxy_pass http://backend; |
|
proxy_set_header Host $host; |
Host |
proxy_set_header X-Real-IP $remote_addr; |
IP |
proxy_connect_timeout 60s; |
|
proxy_read_timeout 90s; |
|
proxy_buffering off; |
(SSE/WebSocket) |
SSL/HTTPS
ssl_certificate /path/cert.pem; |
|
ssl_certificate_key /path/key.pem; |
|
ssl_protocols TLSv1.2 TLSv1.3; |
TLS |
certbot --nginx -d domain.com |
Let's Encrypt |
add_header Strict-Transport-Security ...; |
HSTS |
gzip on; |
|
gzip_types text/css application/javascript; |
|
expires 30d; |
|
proxy_cache_path ... ; |
|
open_file_cache max=1000; |
|