# HG changeset patch # User Vladimir Homutov # Date 1344508608 0 # Node ID 656dfb08502061d7fa766a92d139eda8ed27f120 # Parent 32f50b2f9f0c4a0344b1586d340d7e603daa2c23 Unified server names matching description with server_name directive, improved wording and various typesetting-related changes diff -r 32f50b2f9f0c -r 656dfb085020 xml/en/docs/http/server_names.xml --- a/xml/en/docs/http/server_names.xml Tue Aug 07 12:52:29 2012 +0000 +++ b/xml/en/docs/http/server_names.xml Thu Aug 09 10:36:48 2012 +0000 @@ -8,7 +8,7 @@
@@ -19,8 +19,9 @@ Server names are defined using the directive -and determine which server block is used for a given request. -See also “”. +and determine which block +is used for a given request. +See also “”. They may be defined using exact names, wildcard names, or regular expressions: @@ -48,31 +49,33 @@ ... } + -The names are tested in the following order: - + +When searching for a virtual server by name, if name matches more than one of +the specified variants, e.g. both wildcard name and regular expression match, +the first matching variant will be chosen, in the following order of precedence: -exact names; +exact name -wildcard names starting with an asterisk: *.example.org -(longest first); +longest wildcard name starting with an asterisk, e.g. +“*.example.org -wildcard names ending with an asterisk: mail.* -(longest first); +longest wildcard name ending with an asterisk, e.g. “mail.* -and regular expressions in the order listed in the configuration file. +first matching regular expression +(in order of appearance in a configuration file). -The first match stops the search. @@ -94,8 +97,8 @@ -A special wildcard in the form “.example.org” can be used -to match both the exact name “example.org” +A special wildcard name in the form “.example.org” can be +used to match both the exact name “example.org” and the wildcard name “*.example.org”. @@ -117,11 +120,11 @@ otherwise it will be treated as an exact name, or if the expression contains an asterisk, as a wildcard name (and most likely as an invalid one). -Do not forget to set “^” and “$” anchors. +Do not forget to set “^” and “$” anchors. They are not required syntactically, but logically. Also note that domain name dots should be escaped with a backslash. -A regular expression containing the characters “{” -and “}” should be quoted: +A regular expression containing the characters “{” +and “}” should be quoted: server_name "~^(?<name>\w\d{1,3}+)\.example\.net$"; @@ -172,8 +175,8 @@ pcre_compile() failed: unrecognized character after (?< in ... -this means that the PCRE library is old -and you should try the syntax “?P<name>”. +this means that the PCRE library is old and the syntax +“?P<name>” should be tried instead. The captures can also be used in digital form: @@ -198,8 +201,13 @@ name="Miscellaneous names"> -If you want to process requests without a “Host” header line -in a server block which is not the default, you should specify an empty name: +There are some server names that are treated specially. + + + +If it is required to process requests without the
Host
+header field in a +block which is not the default, an empty name should be specified: server { @@ -213,7 +221,7 @@ If no -is defined in a server block, +is defined in a block then nginx uses the empty name as the server name. nginx versions up to 0.8.48 used the hostname as the server name @@ -223,8 +231,8 @@ If someone makes a request using an IP address instead of a server name, -the request’s “Host” header line will contain the IP address -and you can handle the request using the IP address as the 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: server { @@ -240,7 +248,8 @@
-In catch-all server examples you may see the strange name “_”: +In catch-all server examples the strange name “_” can +be seen: server { @@ -252,23 +261,24 @@ 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. -You may also use something like “--”, “!@#”, and so on. +Other invalid names like “--” and “!@#” +may equally be used. -nginx versions up to 0.6.25 supported the special name “*” +nginx versions up to 0.6.25 supported the special name “*” which was erroneously interpreted to be a catch-all name. It never functioned as a catch-all or wildcard server name. Instead, it supplied the functionality that is now provided by the directive. -The special name “*” is now deprecated +The special name “*” is now deprecated and the directive should be used. Note that there is no way to specify the catch-all name or -the default server using the +the default server using the directive. This is a property of the @@ -277,8 +287,8 @@ and not of the directive. -See also “”. -You can define servers listening on ports *:80 and *:8080, +See also “”. +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: @@ -307,27 +317,27 @@ name="Optimization"> -Exact names and wildcard names are stored in hashes. -The hashes are bound to the listen ports and every listen port -may have up to three hashes: an exact names hash, a wildcard names hash -starting with an asterisk, and a wildcard names hash ending with an asterisk. -The sizes of the hashes are optimized at the configuration phase so that -a name can be found with the fewest CPU cache misses. +Exact names, wildcard names starting with an asterisk, +and wildcard names ending with an asterisk are stored +in three hash tables bound to the listen ports. +The sizes of hash tables are optimized at the configuration phase +so that a name can be found with the fewest CPU cache misses. +See also “”. -The exact names hash is searched first. -If a name is not found using the exact name hash, then the wildcard names hash +The exact names hash table is searched first. +If a name is not found, the hash table with wildcard names starting with an asterisk is searched. -If the name is not found there, the wildcard names hash +If the name is not found there, the hash table with wildcard names ending with an asterisk is searched. -Searching wildcard names hashes is slower than searching exact name hash -because names are searched by domain parts. +Searching wildcard names hash table is slower than searching exact names hash +table because names are searched by domain parts. Note that the special wildcard form “.example.org” -is stored in a wildcard names hash and not in an exact names hash. +is stored in a wildcard names hash table and not in an exact names hash table. @@ -361,17 +371,17 @@ -If you have defined a large number of server names, -or defined unusually long server names, you may need to tune +If a large number of server names are defined, +or unusually long server names are defined, tuning the and -directives at the http level. +directives at the http level may become necessary. The default value of the may be equal to 32, or 64, or another value, -depending on your CPU cache line size. -If the default value is 32 and you define -“too.long.server.name.example.org” as a server name, +depending on CPU cache line size. +If the default value is 32 and server name is defined as +“too.long.server.name.example.org” then nginx will fail to start and display the error message: @@ -379,7 +389,7 @@ you should increase server_names_hash_bucket_size: 32 -In this case, you should set the directive value to the next power of 2: +In this case, the directive value should be increased to the next power of two: http { @@ -387,8 +397,8 @@ ... -If you have defined a large number of server names, -you will get another error message: +If a large number of server names are defined, +another error message will appear: could not build the server_names_hash, @@ -396,18 +406,17 @@ or server_names_hash_bucket_size: 32 -You should first try to set +In such a case, first try to set to a number close to the number of server names. Only if this does not help, -or if nginx’s start time is unacceptably long, -should you try to increase +or if nginx’s start time is unacceptably long, try to increase . If a server is the only server for a listen port, then nginx will not test -server names at all (and will not build the hashes for the listen port). +server names at all (and will not build the hash tables for the listen port). However, there is one exception. If a @@ -425,7 +434,7 @@ -A default server name value is an empty name “” since 0.8.48. +A default server name value is an empty name “” since 0.8.48. @@ -437,7 +446,7 @@ -An empty server name “” has been supported since 0.7.12. +An empty server name “” has been supported since 0.7.12.