官网:Server names
翻译部分:Miscellaneous names
开始!
There are some server names that are treated specially.
有些服务器名称是经过特殊处理的。
If it is required to process requests without the “Host” header field in a server block which is not the default, an empty name should be specified:
如果要在服务器块(不是默认的)中处理不带host头字段的请求,应该指定空名称。
server { listen 80; server_name example.org www.example.org ""; ... }
If no server_name is defined in a server block then nginx uses the empty name as the server name.
如果server块中没有定义server_name,nginx会使用空名称作为服务器名称,即
server_name ""
nginx versions up to 0.8.48 used the machine’s hostname as the server name in this case.
在本例中,0.8.48之前的nginx版本用机器的主机名作为服务器名称。
If a server name is defined as “
$hostname
” (0.9.4), the machine’s hostname is used.
如果server_name $hostname;(0.9.4)则使用机器的主机名作为服务器名。
If someone makes a request using an IP address instead of a server name, the “Host” request header field will contain the IP address and the request can be handled using the IP address as the server name:
如果有人用IP地址而不是服务器名发请求 ,请求的host头字段会包含IP地址,且请求可以被server_name为IP地址的server块处理。
server { listen 80; server_name example.org www.example.org "" 192.168.1.1 ; ... }
In catch-all server examples the strange name “
_
” can be seen:
在catch-all服务器示例中,可以看到奇怪的名字_。
server { listen 80 default_server; server_name _; return 444; }
There is nothing special about this name, it is just one of a myriad of invalid domain names which never intersect with any real name.
这个名称并没有什么特殊之处,它只是众多无效域名中的一个 ,这些域名从未与真实的名称相交过。
Other invalid names like “
--
” and “!@#
” may equally be used.
其他无效名称如--和!@#可以同等的被使用。
nginx versions up to 0.6.25 supported the special name “
*
” which was erroneously interpreted to be a catch-all name.
0.6.25之前的版本支持特殊名称*,该名称被错误的解释为catch-all名称。
It never functioned as a catch-all or wildcard server name.
它从来没有作为一个catch-all名称或者通配符名称发挥作用。
Instead, it supplied the functionality that is now provided by the server_name_in_redirect directive.
相反的,它提供了现在有server_name_in_redirect指令提供的功能。
The special name “
*
” is now deprecated and the server_name_in_redirect directive should be used.
现在不推荐使用特殊名称* ,应该使用server_name_in_rediret指令。
Note that there is no way to specify the catch-all name or the default server using the server_name directive.
请注意,无法使用server_name指令来指定catch-all名称或默认服务器。
This is a property of the listen directive and not of the server_name directive.
这是listen指令的一个属性,而不是server_name指令的属性。
See also “How nginx processes a request”.
也可以看看 How nginx processes a request
It is possible to define servers listening on ports *:80 and *:8080, and direct that one will be the default server for port *:8080, while the other will be the default for port *:80:
可以定义同时监听80和8080端口的服务器,并指示其中一个为8080的默认服务器,而另一个将会是80端口的默认服务器。
server { listen 80; listen 8080 default_server; server_name example.net; ... } server { listen 80 default_server; listen 8080; server_name example.org; ... }