Mercurial > hg > nginx-site
annotate xml/cn/docs/http/server_names.xml @ 2978:2b02fee0d12e
Documented removal of the ssl directive.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 13 Jun 2023 19:24:58 +0100 |
parents | ff357b676c2e |
children |
rev | line source |
---|---|
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
1 <!-- |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
2 Copyright (C) Igor Sysoev |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
3 Copyright (C) Nginx, Inc. |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
4 --> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
5 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
6 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
7 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
8 <article name="虚拟主机名" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
9 link="/cn/docs/http/server_names.html" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
10 lang="cn" |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
11 rev="2" |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
12 translator="cfsego" |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
13 author="Igor Sysoev" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
14 editor="Brian Mercer"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
15 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
16 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
17 <section> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
18 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
19 <para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
20 |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
21 虚拟主机名使用<link doc="ngx_http_core_module.xml" id="server_name"/>指令定义,用于决定由某台<link doc="ngx_http_core_module.xml" id="server">虚拟主机</link>来处理请求。具体请参考《<link doc="request_processing.xml">nginx如何处理一个请求</link>》。虚拟主机名可以使用确切的名字,通配符,或者是正则表达式来定义: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
22 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
23 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
24 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
25 listen 80; |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
26 server_name example.org www.example.org; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
27 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
28 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
29 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
30 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
31 listen 80; |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
32 server_name *.example.org; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
33 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
34 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
35 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
36 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
37 listen 80; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
38 server_name mail.*; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
39 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
40 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
41 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
42 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
43 listen 80; |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
44 server_name ~^(?<user>.+)\.example\.net$; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
45 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
46 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
47 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
48 |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
49 nginx以名字查找虚拟主机时,如果名字可以匹配多于一个主机名定义,比如同时匹配了通配符的名字和正则表达式的名字,那么nginx按照下面的优先级别进行查找,并选中第一个匹配的虚拟主机: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
50 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
51 <list type="enum"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
52 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
53 <listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
54 确切的名字; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
55 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
56 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
57 <listitem> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
58 最长的以星号起始的通配符名字:<literal>*.example.org</literal>; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
59 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
60 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
61 <listitem> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
62 最长的以星号结束的通配符名字:<literal>mail.*</literal>; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
63 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
64 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
65 <listitem> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
66 第一个匹配的正则表达式名字(按在配置文件中出现的顺序)。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
67 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
68 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
69 </list> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
70 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
71 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
72 </section> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
73 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
74 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
75 <section id="wildcard_names" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
76 name="通配符名字"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
77 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
78 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
79 通配符名字只可以在名字的起始处或结尾处包含一个星号,并且星号与其他字符之间用点分隔。所以,“<literal>www.*.example.org</literal>”和“<literal>w*.example.org</literal>”都是非法的。不过,上面的两个名字可以使用正则表达式描述,即“<literal>~^www\..+\.example\.org$</literal>”和“<literal>~^w.*\.example\.org$</literal>”。星号可以匹配名字的多个节(各节都是以点号分隔的)。“<literal>*.example.org</literal>”不仅匹配<literal>www.example.org</literal>,也匹配<literal>www.sub.example.org</literal>。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
80 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
81 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
82 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
83 有一种形如“<literal>.example.org</literal>”的特殊通配符,它可以既匹配确切的名字“<literal>example.org</literal>”,又可以匹配一般的通配符名字“<literal>*.example.org</literal>”。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
84 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
85 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
86 </section> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
87 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
88 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
89 <section id="regex_names" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
90 name="正则表达式名字"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
91 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
92 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
93 nginx使用的正则表达式兼容PCRE。为了使用正则表达式,虚拟主机名必须以波浪线“~”起始: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
94 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
95 <programlisting> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
96 server_name ~^www\d+\.example\.net$; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
97 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
98 |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
99 否则该名字会被认为是个确切的名字,如果表达式含星号,则会被认为是个通配符名字(而且很可能是一个非法的通配符名字)。不要忘记设置“<literal>^</literal>”和“<literal>$</literal>”锚点,语法上它们不是必须的,但是逻辑上是的。同时需要注意的是,域名中的点“.”需要用反斜线“\”转义。含有“<literal>{</literal>”和“<literal>}</literal>”的正则表达式需要被引用,如: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
100 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
101 <programlisting> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
102 server_name "~^(?<name>\w\d<b>{</b>1,3<b>}</b>+)\.example\.net$"; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
103 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
104 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
105 否则nginx就不能启动,错误提示是: |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
106 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
107 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
108 directive "server_name" is not terminated by ";" in ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
109 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
110 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
111 命名的正则表达式捕获组在后面可以作为变量使用: |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
112 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
113 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
114 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
115 server_name ~^(www\.)?(<b>?<domain></b>.+)$; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
116 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
117 location / { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
118 root /sites/<b>$domain</b>; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
119 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
120 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
121 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
122 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
123 PCRE使用下面语法支持命名捕获组: |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
124 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
125 <table note="yes"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
126 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
127 <tr> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
128 <td><literal>?<<value>name</value>></literal></td> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
129 <td>从PCRE-7.0开始支持,兼容Perl 5.10语法</td> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
130 </tr> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
131 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
132 <tr> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
133 <td><literal>?'<value>name</value>'</literal></td> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
134 <td>从PCRE-7.0开始支持,兼容Perl 5.10语法</td> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
135 </tr> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
136 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
137 <tr> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
138 <td><literal>?P<<value>name</value>></literal></td> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
139 <td>从PCRE-4.0开始支持,兼容Python语法</td> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
140 </tr> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
141 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
142 </table> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
143 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
144 如果nginx不能启动,并显示错误信息: |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
145 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
146 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
147 pcre_compile() failed: unrecognized character after (?< in ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
148 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
149 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
150 说明PCRE版本太旧,应该尝试使用<literal>?P<name></literal>。捕获组也可以以数字方式引用: |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
151 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
152 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
153 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
154 server_name ~^(www\.)?(.+)$; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
155 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
156 location / { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
157 root /sites/<b>$2</b>; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
158 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
159 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
160 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
161 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
162 不过,这种用法只限于简单的情况(比如上面的例子),因为数字引用很容易被覆盖。 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
163 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
164 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
165 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
166 </section> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
167 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
168 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
169 <section id="miscellaneous_names" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
170 name="其他类型的名字"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
171 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
172 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
173 有一些主机名会被特别对待。 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
174 </para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
175 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
176 <para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
177 如果需要用一个非默认的<link doc="ngx_http_core_module.xml" id="server">虚拟主机</link>处理请求头中不含<header>Host</header>字段的请求,需要指定一个空名字: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
178 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
179 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
180 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
181 listen 80; |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
182 server_name example.org www.example.org ""; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
183 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
184 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
185 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
186 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
187 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
188 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
189 如果<link doc="ngx_http_core_module.xml" id="server"/>块中没有定义<link doc="ngx_http_core_module.xml" id="server_name"/>,nginx使用空名字作为虚拟主机名。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
190 <note> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
191 nginx 0.8.48版本以下(含)在同样的情况下会使用机器名作为虚拟主机名。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
192 </note> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
193 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
194 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
195 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
196 如果以“<literal>$hostname</literal>”(nginx 0.9.4及以上版本)定义虚拟主机名,机器名将被使用。 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
197 </para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
198 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
199 <para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
200 如果使用IP地址而不是主机名来请求服务器,那么请求头的<header>Host</header>字段包含的将是IP地址。可以将IP地址作为虚拟主机名来处理这种请求: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
201 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
202 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
203 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
204 listen 80; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
205 server_name nginx.org |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
206 www.nginx.org |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
207 "" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
208 <b>192.168.1.1</b> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
209 ; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
210 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
211 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
212 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
213 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
214 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
215 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
216 在匹配所有的服务器的例子中,可以见到一个奇怪的名字“<literal>_</literal>”: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
217 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
218 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
219 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
220 listen 80 default_server; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
221 server_name _; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
222 return 444; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
223 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
224 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
225 |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
226 这没什么特别的,它只不过是成千上万的与真实的名字绝无冲突的非法域名中的一个而已。当然,也可以使用“<literal>--</literal>”和“<literal>!@#</literal>”等等。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
227 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
228 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
229 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
230 nginx直到0.6.25版本还支持一个特殊的名字“<literal>*</literal>”,这个名字一直被错误地理解成是一个匹配所有的名字。但它从来没有像匹配所有的名字,或者通配符那样工作过,而是用来支持一种功能,此功能现在已经改由<link doc="ngx_http_core_module.xml" id="server_name_in_redirect"/>指令提供支持了。所以,现在这个特殊的名字“<literal>*</literal>”已经过时了,应该使用<link doc="ngx_http_core_module.xml" id="server_name_in_redirect"/>指令取代它。需要注意的是,使用<link doc="ngx_http_core_module.xml" id="server_name"/>指令无法描述匹配所有的名字或者默认服务器。这是<link doc="ngx_http_core_module.xml" id="listen"/>指令的属性,而不是<link doc="ngx_http_core_module.xml" id="server_name"/>指令的属性。具体请参考《<link doc="request_processing.xml">nginx如何处理一个请求</link>》。可以定义两个服务器都监听*:80和*:8080端口,然后指定一个作为端口*:8080的默认服务器,另一个作为端口*:80的默认服务器: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
231 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
232 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
233 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
234 listen 80; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
235 listen 8080 default_server; |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
236 server_name example.net; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
237 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
238 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
239 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
240 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
241 listen 80 default_server; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
242 listen 8080; |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
243 server_name example.org; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
244 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
245 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
246 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
247 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
248 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
249 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
250 </section> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
251 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
252 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
253 <section id="optimization" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
254 name="优化"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
255 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
256 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
257 确切名字和通配符名字存储在哈希表中。哈希表和监听端口关联。哈希表的尺寸在配置阶段进行了优化,可以以最小的CPU缓存命中失败来找到名字。设置哈希表的细节参见<link doc="../hash.xml">这篇文档</link> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
258 </para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
259 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
260 <para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
261 nginx首先搜索确切名字的哈希表,如果没有找到,搜索以星号起始的通配符名字的哈希表,如果还是没有找到,继续搜索以星号结束的通配符名字的哈希表。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
262 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
263 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
264 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
265 因为名字是按照域名的节来搜索的,所以搜索通配符名字的哈希表比搜索确切名字的哈希表慢。注意特殊的通配符名字“<literal>.example.org</literal>”存储在通配符名字的哈希表中,而不在确切名字的哈希表中。 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
266 </para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
267 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
268 <para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
269 正则表达式是一个一个串行的测试,所以是最慢的,而且不可扩展。 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
270 </para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
271 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
272 <para> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
273 鉴于以上原因,请尽可能使用确切的名字。举个例子,如果使用<literal>example.org</literal>和<literal>www.example.org</literal>来访问服务器是最频繁的,那么将它们明确的定义出来就更为有效: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
274 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
275 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
276 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
277 listen 80; |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
278 server_name example.org www.example.org *.example.org; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
279 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
280 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
281 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
282 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
283 下面这种方法相比更简单,但是效率也更低: |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
284 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
285 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
286 server { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
287 listen 80; |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
288 server_name .example.org; |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
289 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
290 } |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
291 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
292 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
293 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
294 <para> |
2735 | 295 如果定义了大量名字,或者定义了非常长的名字,那可能需要在<i>http</i>配置块中使用<link doc="ngx_http_core_module.xml" id="server_names_hash_max_size"/>和<link doc="ngx_http_core_module.xml" id="server_names_hash_bucket_size"/>指令进行调整。<link doc="ngx_http_core_module.xml" id="server_names_hash_bucket_size"/>的默认值可能是32,或者是64,或者是其他值,取决于CPU的缓存行的长度。如果这个值是32,那么定义“<literal>too.long.server.name.example.org</literal>”作为虚拟主机名就会失败,而nginx显示下面错误信息: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
296 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
297 could not build the server_names_hash, |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
298 you should increase server_names_hash_bucket_size: 32 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
299 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
300 |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
301 出现了这种情况,那就需要将指令的值扩大一倍: |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
302 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
303 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
304 http { |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
305 server_names_hash_bucket_size 64; |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
306 ... |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
307 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
308 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
309 如果定义了大量名字,得到了另外一个错误: |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
310 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
311 <programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
312 could not build the server_names_hash, |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
313 you should increase either server_names_hash_max_size: 512 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
314 or server_names_hash_bucket_size: 32 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
315 </programlisting> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
316 |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
317 那么应该先尝试设置<link doc="ngx_http_core_module.xml" id="server_names_hash_max_size"/>的值差不多等于名字列表的名字总量。如果还不能解决问题,或者服务器启动非常缓慢,再尝试提高<link doc="ngx_http_core_module.xml" id="server_names_hash_bucket_size"/>的值。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
318 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
319 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
320 <para> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
321 如果只为一个监听端口配置了唯一的主机,那么nginx就完全不会测试虚拟主机名了(也不会为监听端口建立哈希表)。不过,有一个例外,如果定义的虚拟主机名是一个含有捕获组的正则表达式,这时nginx就不得不执行这个表达式以得到捕获组。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
322 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
323 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
324 </section> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
325 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
326 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
327 <section id="compatibility" |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
328 name="兼容性"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
329 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
330 <para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
331 <list type="bullet"> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
332 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
333 <listitem> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
334 从0.9.4版本开始,支持特殊的虚拟主机名“<literal>$hostname</literal>”。 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
335 </listitem> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
336 |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
337 <listitem> |
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
338 从0.8.48版本开始,默认的虚拟主机名是空名字“”。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
339 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
340 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
341 <listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
342 从0.8.25版本开始,支持虚拟主机名中使用命名的正则表达式捕获组。 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
343 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
344 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
345 <listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
346 从0.7.40版本开始,支持虚拟主机名中使用正则表达式的捕获组。 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
347 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
348 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
349 <listitem> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
350 从0.7.12版本开始,支持空名字“”。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
351 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
352 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
353 <listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
354 从0.6.25版本开始,通配符和正则表达式名字可以作为第一个虚拟主机名。 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
355 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
356 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
357 <listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
358 从0.6.7版本开始,支持正则表达式的虚拟主机名。 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
359 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
360 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
361 <listitem> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
362 从0.6.0版本开始,支持形如<literal>example.*</literal>的通配符名字。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
363 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
364 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
365 <listitem> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
366 从0.3.18版本开始,支持形如<literal>.example.org</literal>的特殊通配符名字。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
367 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
368 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
369 <listitem> |
720
9934338f83af
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
593
diff
changeset
|
370 从0.1.13版本开始,支持形如<literal>*.example.org</literal>的通配符名字。 |
558
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
371 </listitem> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
372 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
373 </list> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
374 </para> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
375 |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
376 </section> |
149f54c158f0
Added initial translation in simplified Chinese submitted by the
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
377 |
2735 | 378 </article> |