在Nginx中,变量$host
和$http_host
有什么区别。
最佳答案
$host
是 Core 的变量模块。
$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
也是同一模块的变量,但您不会用该名称找到它,因为它一般定义为 $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...;
总结:
$http_host
始终等于HTTP_HOST
请求 header 。$host
等于$http_host
,小写且不带端口号(如果存在),除非HTTP_HOST
不存在或者为空值。在这种情况下,$host
等于处理请求的服务器的server_name
指令的值。
关于configuration - Nginx 中 $host 和 $http_host 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15414810/