nginx Reference
Browse nginx directives with syntax, defaults, context badges, and configuration examples.
40 directives found
worker_processesmainSets the number of worker processes. 'auto' detects CPU cores.
Syntax
worker_processes <number> | autoDefault
1Example
worker_processes auto;
worker_connectionseventsMaximum number of simultaneous connections per worker process.
Syntax
worker_connections <number>Default
512Example
worker_connections 1024;
keepalive_timeouthttpserverlocationTimeout for keep-alive connections with the client.
Syntax
keepalive_timeout <timeout>Default
75sExample
keepalive_timeout 65;
client_max_body_sizehttpserverlocationMaximum allowed size of the client request body. 0 disables the check.
Syntax
client_max_body_size <size>Default
1mExample
client_max_body_size 10m;
sendfilehttpserverlocationEnables the use of sendfile() for serving static files efficiently.
Syntax
sendfile on | offDefault
offExample
sendfile on;
tcp_nopushhttpserverlocationEnables TCP_CORK socket option to send headers and the beginning of a file in one packet.
Syntax
tcp_nopush on | offDefault
offExample
tcp_nopush on;
gziphttpserverlocationEnable gzip compression for responses.
Syntax
gzip on | offDefault
offExample
gzip on;
gzip_typeshttpserverlocationMIME types to compress (text/html is always compressed).
Syntax
gzip_types <mime-type> ...Default
text/htmlExample
gzip_types text/plain text/css application/json application/javascript;
listenserverSets the address and port for IP or the path for UNIX-domain socket.
Syntax
listen <address>[:<port>] [ssl] [http2]Default
80 | 8000Example
listen 443 ssl http2;
server_nameserverSets names of a virtual server. Supports wildcards and regex.
Syntax
server_name <name> ...Default
""Example
server_name example.com www.example.com;
roothttpserverlocationSets the root directory for requests.
Syntax
root <path>Default
htmlExample
root /var/www/html;
indexhttpserverlocationDefines files that will be used as an index.
Syntax
index <file> ...Default
index.htmlExample
index index.html index.php;
try_filesserverlocationChecks the existence of files in the specified order. Last parameter is a fallback.
Syntax
try_files <file> ... <uri> | =<code>Example
try_files $uri $uri/ /index.html;
returnserverlocationStops processing and returns the specified code to a client.
Syntax
return <code> [<url>]Example
return 301 https://$host$request_uri;
rewriteserverlocationRewrites the URI using regex. Flags: last, break, redirect, permanent.
Syntax
rewrite <regex> <replacement> [flag]Example
rewrite ^/old-path/(.*)$ /new-path/$1 permanent;
error_pagehttpserverlocationDefines a URI for custom error pages.
Syntax
error_page <code> ... <uri>Example
error_page 404 /404.html; error_page 500 502 /50x.html;
locationserverlocationSets configuration for a URI. Modifiers: = (exact), ~ (regex), ~* (regex case-insensitive), ^~ (prefix, no regex).
Syntax
location [= | ~ | ~* | ^~] <uri> { ... }Example
location /api/ { proxy_pass http://backend; }proxy_passlocationSets the protocol and address of a proxied server.
Syntax
proxy_pass <URL>Example
proxy_pass http://localhost:3000;
proxy_set_headerhttpserverlocationRedefines or appends fields to the request header passed to the proxied server.
Syntax
proxy_set_header <field> <value>Example
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;
proxy_http_versionhttpserverlocationSets the HTTP protocol version for proxying. Use 1.1 for keepalive upstream connections.
Syntax
proxy_http_version 1.0 | 1.1Default
1.0Example
proxy_http_version 1.1;
proxy_read_timeouthttpserverlocationTimeout for reading a response from the proxied server between two successive read operations.
Syntax
proxy_read_timeout <time>Default
60sExample
proxy_read_timeout 120s;
proxy_connect_timeouthttpserverlocationTimeout for establishing a connection to the proxied server.
Syntax
proxy_connect_timeout <time>Default
60sExample
proxy_connect_timeout 10s;
proxy_bufferinghttpserverlocationEnables or disables buffering of responses from the proxied server.
Syntax
proxy_buffering on | offDefault
onExample
proxy_buffering off; # for SSE/streaming
upstreamhttpDefines a group of servers for load balancing.
Syntax
upstream <name> { server <address>; ... }Example
upstream backend {
server 10.0.0.1:3000;
server 10.0.0.2:3000;
}ssl_certificateserverSpecifies a file with the certificate in PEM format.
Syntax
ssl_certificate <file>Example
ssl_certificate /etc/ssl/certs/example.crt;
ssl_certificate_keyserverSpecifies a file with the secret key in PEM format.
Syntax
ssl_certificate_key <file>Example
ssl_certificate_key /etc/ssl/private/example.key;
ssl_protocolshttpserverEnables the specified protocols. Disable TLSv1 and TLSv1.1 for security.
Syntax
ssl_protocols [TLSv1] [TLSv1.1] [TLSv1.2] [TLSv1.3]Default
TLSv1 TLSv1.1 TLSv1.2 TLSv1.3Example
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphershttpserverSpecifies the enabled ciphers. Use modern cipher suites.
Syntax
ssl_ciphers <ciphers>Default
HIGH:!aNULL:!MD5Example
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_session_cachehttpserverSets the types and sizes of caches that store session parameters.
Syntax
ssl_session_cache off | none | <type:size>Default
noneExample
ssl_session_cache shared:SSL:10m;
ssl_staplinghttpserverEnables stapling of OCSP responses by the server.
Syntax
ssl_stapling on | offDefault
offExample
ssl_stapling on; ssl_stapling_verify on;
denyhttpserverlocationDenies access for the specified network or address.
Syntax
deny <address> | CIDR | allExample
deny 192.168.0.0/16; deny all;
allowhttpserverlocationAllows access for the specified network or address.
Syntax
allow <address> | CIDR | allExample
allow 10.0.0.0/8; allow 127.0.0.1; deny all;
limit_reqhttpserverlocationLimits the rate of requests for a zone defined by limit_req_zone.
Syntax
limit_req zone=<name> [burst=<n>] [nodelay]Example
limit_req zone=api burst=20 nodelay;
limit_req_zonehttpSets parameters for a shared memory zone used for limiting the request rate.
Syntax
limit_req_zone <key> zone=<name>:<size> rate=<rate>Example
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
add_headerhttpserverlocationAdds the specified field to a response header. 'always' adds even for error responses.
Syntax
add_header <name> <value> [always]Example
add_header X-Frame-Options "SAMEORIGIN" always; add_header Strict-Transport-Security "max-age=31536000" always;
expireshttpserverlocationEnables or disables adding or modifying the Expires and Cache-Control response headers.
Syntax
expires [modified] <time> | epoch | max | offDefault
offExample
expires 30d; # static assets expires -1; # no cache
more_set_headershttpserverlocationSets output header fields. Part of ngx_headers_more module (not built-in).
Syntax
more_set_headers '<name>: <value>'Example
more_set_headers "Server: myserver";
access_loghttpserverlocationSets the path, format, and configuration for request logging.
Syntax
access_log <path> [<format>] | offDefault
logs/access.log combinedExample
access_log /var/log/nginx/access.log combined; access_log off;
error_logmainhttpserverlocationConfigures logging. Levels: debug, info, notice, warn, error, crit, alert, emerg.
Syntax
error_log <file> [<level>]Default
logs/error.log errorExample
error_log /var/log/nginx/error.log warn;
log_formathttpSpecifies a log format. Variables like $remote_addr, $request, $status are available.
Syntax
log_format <name> <string> ...Example
log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent';