9.nginx如何处理一个请求--基于名称的虚拟服务器

官网:How nginx processes a request

翻译部分:Name-based virtual servers(基于名称的虚拟服务器)

开始!


nginx first decides which server should process the request.

 nginx首先决定哪个server块应该处理请求。


Let’s start with a simple configuration where all three virtual servers listen on port *:80:

 让我们以一个简单的配置文件开始,配置文件的所有3个虚拟服务器都监听80端口。

server {
    listen      80;
    server_name example.org www.example.org;
    ...
}

server {
    listen      80;
    server_name example.net www.example.net;
    ...
}

server {
    listen      80;
    server_name example.com www.example.com;
    ...
}

In this configuration nginx tests only the request’s header field “Host” to determine which server the request should be routed to.

 在这个配置文件中,nginx只测试请求头的host字段来决定路由请求到哪个虚拟服务器,host如下图:


If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port.

 如果请求的host都没有匹配到server_name,或者请求根本不包含这个头字段,然后,nginx会路由这个请求到这个端口的默认服务器(即server块)。


In the configuration above, the default server is the first one — which is nginx’s standard default behaviour.

 上面的配置文件的默认服务器是第一个-这是nginx的标准默认行为。


It can also be set explicitly which server should be default, with the default_server parameter in the listen directive:

 还可以用在listen指令上default_server参数来明确设置默认服务器,如下:

server {
    listen      80 default_server;
    server_name example.net www.example.net;
    ...
}
The  default_server parameter has been available since version 0.8.21. In earlier versions the  default parameter should be used instead.

 default_server参数自0.8.21版本使用,在这之前的版本用default参数。


Note that the default server is a property of the listen port and not of the server name.

 注意,default_server是监听端口listen指令的一个属性,而不是server_name指令的属性。


More about this later.

接下来会有更多内容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值