nginx Directives Reference

Searchable nginx directive reference with context, syntax and default values.

Reference for nginx core, http, server, location and upstream directives — including proxy_pass, try_files, rewrite and gzip — with valid context, syntax, default value and source module.

What does context mean for an nginx directive?

Context is the block — main, events, http, server, location or upstream — where a directive may legally appear. Placing a directive in the wrong block makes nginx refuse to start with a 'directive is not allowed here' error.

A fast, offline nginx directive lookup

nginx is configured entirely through directives, and each one is only valid in certain blocks. This reference lets you search by directive name, module or description and filter by the context where it applies, so you can wire up a reverse proxy, static host or rewrite rule without digging through the manual. It runs locally in your browser; no configuration is sent anywhere.

How it works

Every entry shows the directive name, the source module (e.g. ngx_http_proxy), the syntax with placeholders, the contexts in which the directive is valid, and the default value where one exists. nginx evaluates configuration as nested blocks: main -> events/http -> server -> location. Inner blocks inherit values from their parents and may override them. A minimal reverse proxy looks like:

server {
  listen 80;
  server_name example.com;
  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host $host;
  }
}

After editing, validate with nginx -t and apply with nginx -s reload.

Tips and examples

  • Use try_files $uri $uri/ /index.html; to serve a single-page app and fall back to the app shell for client-side routes.
  • return 301 https://$host$request_uri; in a port-80 server block forces all traffic to HTTPS.
  • Set client_max_body_size higher than the default 1m when accepting file uploads, or large requests fail with a 413.
  • add_header ... always ensures the header is also sent on error responses, which matters for security headers like HSTS.