Skip to content

Nginx Variables API

Built-in Nginx variables exposing request and connection properties usable in directives.

1 class · 6 methods

Variables

6 methods

Commonly used built-in variables available in the http context.

$host

Lowercase host name from the request line, or Host header, or server name matched.

Returns

string

Example

nginx
add_header X-Served-For $host;
$request_uri

Full original request URI including query string, unmodified.

Returns

string

Example

nginx
return 301 https://$host$request_uri;
$remote_addr

Client IP address of the connection.

Returns

string

Example

nginx
log_format main '$remote_addr - $remote_user [$time_local] "$request"';
$args | $query_string

Full query string from the request line; identical values.

Returns

string

Example

nginx
if ($args ~* ^debug=1) { add_header X-Debug on; }
$scheme

Request scheme: http or https.

Returns

string

Example

nginx
return 301 $scheme://example.com$request_uri;
$http_<name>

Value of the request header whose lowercased name with dashes replaced by underscores is <name>.

Parameters

NameTypeDescription
namestringHeader name with dashes converted to underscores (e.g. x_request_id for X-Request-Id).

Returns

string

Example

nginx
proxy_set_header X-Request-Id $http_x_request_id;