Nginx 中的 $host 和 $http_host 有什么区别 [英] What's the difference of $host and $http_host in Nginx

查看:157
本文介绍了Nginx 中的 $host 和 $http_host 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 the HTTP_HOST request header.
  • $host equals $http_host, lowercase and without the port number (if present), except when HTTP_HOST is absent or is an empty value. In that case, $host equals the value of the server_name directive of the server which processed the request.

这篇关于Nginx 中的 $host 和 $http_host 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆