NGINX Internal Env Args

Useful Arguments

The variable $http_host contains the host in the original request, whereas $uri contains the path after the domain or IP. The last two variables $is_args and $args check for any additional arguments in the initial request, and they add them automatically to the proxied request.

$uri vs $request_uri

$uri is not equivalent to $request_uri.
The $uri variable is set to the URI that nginx is currently processing - but it is also subject to normalisation, including:

  • Removal of the ? and query string
  • Consecutive / characters are replace by a single /
  • URL encoded characters are decoded

The value of $request_uri is always the original URI and is not subject to any of the above normalisations.

Most of the time you would use $uri, because it is normalised. Using $request_uri in the wrong place can cause URL encoded characters to become doubly encoded.

Use $request_uri in a map directive, if you need to match the URI and its query string.

$host vs $http_host

$host is a variable of the Core module.

This variable may have a different value from $http_host in such cases:

  1. when the Host input header is absent or has an empty value, $host equals to the value of server_name directive;
  2. when the value of Host contains port number, $host doesn’t include that port number. $host’s value is always lowercase since 0.8.17.

$http_host is also a variable of the same module but you won’t find it with that name because it is defined generically as $http_HEADER (ref).

The value of the HTTP request header HEADER when converted to lowercase and with ‘dashes’ converted to ‘underscores’, e.g. $http_user_agent, $http_referer…;

  • $host contains “in this order of precedence: host name from the request line, or host name from the ‘Host’ request header field, or the server name matching a request”
  • $http_host contains the content of the HTTP “Host” header field, if it was present in the request
  • $server_name contains the server_name of the virtual host which processed the request, as it was defined in the nginx configuration. If a server contains multiple server_names, only the first one will be present in this variable.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值