xutil.dev
Login

Nginx Configuration Cheatsheet

Quick reference for Nginx directives covering basic config, location blocks, reverse proxy, SSL/TLS, caching, security, performance, and logging

64 commands

server { }

Define a server block

listen

Specify listening port

listen (IPv6)

Listen on IPv6

server_name

Set server name (domain)

root

Set document root

index

Set default index files

worker_processes

Set number of worker processes

worker_connections

Max connections per worker

include

Include external config files

nginx -t

Test configuration syntax

nginx -s reload

Reload configuration

nginx -s stop

Stop Nginx

location /

Prefix match location

location = /path

Exact match location

location ~ regex

Regex match (case-sensitive)

location ~* regex

Regex match (case-insensitive)

location ^~ /path

Priority prefix match

try_files

Try files in order

alias

Replace location path with alias

return

Return specified status code

rewrite

Rewrite URL

proxy_pass

Forward requests to backend

proxy_set_header Host

Set Host header

proxy_set_header X-Real-IP

Forward client IP to backend

proxy_set_header X-Forwarded-For

Forward proxy chain IPs

proxy_set_header X-Forwarded-Proto

Forward original protocol

upstream

Define upstream server group

proxy_read_timeout

Backend read timeout

proxy_connect_timeout

Backend connect timeout

proxy_buffering

Enable/disable proxy buffering

listen 443 ssl

Listen on 443 with SSL

ssl_certificate

SSL certificate file path

ssl_certificate_key

SSL private key file path

ssl_protocols

Allowed SSL/TLS protocols

ssl_ciphers

Specify cipher suites

ssl_prefer_server_ciphers

Prefer server cipher suites

ssl_session_cache

Set SSL session cache

ssl_session_timeout

SSL session timeout

expires

Set response expiration

add_header Cache-Control

Add Cache-Control header

proxy_cache_path

Set proxy cache path

proxy_cache

Specify proxy cache zone

proxy_cache_valid

Set cache validity period

proxy_cache_bypass

Conditions to bypass cache

deny

Deny access from specified IP

allow

Allow access from specified IP

auth_basic

Enable Basic authentication

auth_basic_user_file

Specify Basic auth user file

add_header X-Frame-Options

Clickjacking protection header

add_header X-Content-Type-Options

MIME sniffing prevention header

limit_req_zone

Define rate limit zone

limit_req

Apply rate limiting

gzip

Enable gzip compression

gzip_types

Specify MIME types for gzip

gzip_min_length

Minimum size for gzip

sendfile

Enable sendfile (fast file transfer)

tcp_nopush

Enable TCP_NOPUSH

tcp_nodelay

Enable TCP_NODELAY

keepalive_timeout

Set Keep-Alive timeout

access_log

Set access log path

error_log

Set error log path and level

log_format

Define custom log format

access_log off

Disable access log

open_log_file_cache

Set log file cache