开发者社区> 问答> 正文

nginx中$host、$http_host 、$server_name 这三个变量有什么不同

比如下面一段配置

if (!-e $request_filename) {
    rewrite /admin$ $scheme://$host$uri/ permanent;
    rewrite ^(/[^/]+)?(/sp-.*) $2 last;
    rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}

why would $http_host be more dangerous?

展开
收起
a123456678 2016-06-23 14:20:47 14479 0
1 条回答
写回答
取消 提交回答
  • $host的值有可能变化,先取请求头的host,如果没有去取接受请求的那个server的名称
    $server_name表示接受请求的那个server的名称
    至于$http_host,官方文档也没有这个值, 是不是题主写错了。 我只发现$http_name
    下面贴上官方文档对着三个变量的定义:
    $host
    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_name
    arbitrary request header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
    $server_name
    name of the server which accepted a request

    2019-07-17 19:46:14
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载