Nginx 中的 $host 和 $http_host 有什么区别 [英] What's the difference of $host and $http_host in Nginx
问题描述
在Nginx中,变量$host
和$http_host
有什么区别.
$host
是 核心 模块.
$主机
<块引用>
这个变量等于请求头中的Host行或者如果 Host 标头不是,则处理请求的服务器的名称可用.
<块引用>
这个变量的值可能与 $http_host 不同情况:1)当Host输入头不存在或值为空时,$host 等于 server_name 指令的值;2)当值of Host 包含端口号,$host 不包含该端口号.从 0.8.17 开始,$host 的值总是小写.
$http_host
也是同一个模块的一个变量,但你不会用那个名字找到它,因为它通常被定义为 $http_HEADER
(ref).
$http_HEADER
<块引用>
HTTP 请求标头 HEADER 的值,当转换为小写并且破折号"转换为下划线"时,例如$http_user_agent, $http_referer...;
总结:
$http_host
始终等于HTTP_HOST
请求标头.$host
等于$http_host
,小写且不带端口号(如果存在),HTTP_HOST 除外
不存在或为空值.在这种情况下,$host
等于处理请求的服务器的server_name
指令的值.
In Nginx, what's the difference between variables $host
and $http_host
.
$host
is a variable of the Core module.
$host
This variable is equal to line Host in the header of request or name of the server processing the request if the Host header is not available.
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).
$http_HEADER
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...;
Summarizing:
$http_host
equals always theHTTP_HOST
request header.$host
equals$http_host
, lowercase and without the port number (if present), except whenHTTP_HOST
is absent or is an empty value. In that case,$host
equals the value of theserver_name
directive of the server which processed the request.
这篇关于Nginx 中的 $host 和 $http_host 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!