$ host和$ http_host在Nginx中有什么区别 [英] What's the difference of $host and $http_host in Nginx
问题描述
在Nginx中,变量 $ host
和 $ http_host
之间的区别是什么。
In Nginx, what's the difference between variables $host
and $http_host
.
推荐答案
$ host
是 Core 模块。
$ host
$host
此变量等于请求头中的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.
在这种
情况下,此变量可能与$ http_host具有不同的值:1)当主机输入头缺少或有一个空值时,
$ host等于server_name指令; 2)当主机的值
包含端口号时,$ host不包括该端口号。
$ host的值从0.8.17开始总是小写。
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
也是同一个模块的一个变量,但你不会找到它的名称,因为它一般定义为 $ http_HEADER
(ref )。
$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
$http_HEADER
HTTP请求头HEADER的值转换为小写并将'dashes'转换为'下划线',例如$ http_user_agent,$ http_referer ...;
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
等于始终使用HTTP_HOST
请求 -
$ host
等于$ http_host
没有端口号(如果存在),除非HTTP_HOST
不存在或为空值。在这种情况下,$ host
等于处理请求的服务器的server_name
指令的值。
$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.
这篇关于$ host和$ http_host在Nginx中有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!