nginx Built-in Variables Reference

All nginx $variable names with source module and description.

Searchable nginx built-in variable reference covering core HTTP, proxy, upstream, SSL and GeoIP variables, including the dynamic $http_, $arg_, $cookie_ and $sent_http_ name patterns.

What is the difference between $uri and $request_uri?

$request_uri is the full original request URI including the query string and exactly as the client sent it. $uri is the current normalised URI without the query string, and it can change during internal redirects and rewrites, so the two often differ after a rewrite.

nginx built-in variables

nginx exposes a large set of $variables you can reference in directives like log_format, proxy_set_header, return, map and if. They expose request metadata, proxy and upstream details, and TLS information. This reference groups the common ones by source module and explains each.

How it works

Variables are evaluated per request. Some are fixed names ($remote_addr, $status); others follow a dynamic pattern where part of the name is supplied by you:

log_format main '$remote_addr "$request" $status '
                '$body_bytes_sent "$http_user_agent" '
                'rt=$request_time urt=$upstream_response_time';

location /api/ {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://backend;
}

The dynamic prefixes are $http_NAME (request headers), $sent_http_NAME (response headers), $arg_NAME (query arguments) and $cookie_NAME (cookies), where NAME is lowercased with hyphens replaced by underscores.

Tips and notes

  • $request_uri keeps the query string and original form; $uri is normalised and rewrite-aware.
  • Use $proxy_add_x_forwarded_for to correctly append the client IP when chaining proxies.
  • Upstream timing variables ($upstream_response_time, $upstream_connect_time) are great for latency logs.
  • The $ssl_ family only has values on HTTPS server blocks with TLS negotiated.