Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/cn/docs/http/ngx_http_browser_module.xml
1 views
1
<?xml version="1.0"?>
2
3
<!--
4
Copyright (C) Igor Sysoev
5
Copyright (C) Nginx, Inc.
6
-->
7
8
<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
9
10
<module name="ngx_http_browser_module模块"
11
link="/cn/docs/http/ngx_http_browser_module.html"
12
lang="cn"
13
translator="litianqing"
14
rev="1">
15
16
<section id="summary">
17
18
<para>
19
模块<literal>ngx_http_browser_module</literal>创建变量,它们的值取决于
20
请求头中<header>User-Agent</header>的值:
21
<list type="tag">
22
23
<tag-name><var>$modern_browser</var></tag-name>
24
<tag-desc>
25
如果浏览器被为识别为新式浏览器,该值等于<link id="modern_browser_value"/>指令设置的值;
26
</tag-desc>
27
28
<tag-name><var>$ancient_browser</var></tag-name>
29
<tag-desc>
30
如果浏览器被识别为旧式浏览器,该值等于<link id="ancient_browser_value"/>指令设置的值;
31
</tag-desc>
32
33
<tag-name><var>$msie</var></tag-name>
34
<tag-desc>
35
如果浏览器被识别为任何版本的MSIE,该值等于“1”。
36
</tag-desc>
37
38
</list>
39
</para>
40
41
</section>
42
43
44
<section id="example" name="配置示例">
45
46
<para>
47
选择一个默认页:
48
<example>
49
modern_browser_value "modern.";
50
51
modern_browser msie 5.5;
52
modern_browser gecko 1.0.0;
53
modern_browser opera 9.0;
54
modern_browser safari 413;
55
modern_browser konqueror 3.0;
56
57
index index.${modern_browser}html index.html;
58
</example>
59
</para>
60
61
<para>
62
旧式浏览器的重定向:
63
<example>
64
modern_browser msie 5.0;
65
modern_browser gecko 0.9.1;
66
modern_browser opera 8.0;
67
modern_browser safari 413;
68
modern_browser konqueror 3.0;
69
70
modern_browser unlisted;
71
72
ancient_browser Links Lynx netscape4;
73
74
if ($ancient_browser) {
75
rewrite ^ /ancient.html;
76
}
77
</example>
78
</para>
79
80
</section>
81
82
83
<section id="directives" name="指令">
84
85
<directive name="ancient_browser">
86
<syntax><value>string</value> ...</syntax>
87
<default/>
88
<context>http</context>
89
<context>server</context>
90
<context>location</context>
91
92
<para>
93
如果任一指定的子串在请求头的<header>User-Agent</header>域中被发现,浏览器将被认定为旧式浏览器。
94
特殊字符串“<literal>netscape4</literal>” 相当于正则表达式“<literal>^Mozilla/[1-4]</literal>”。
95
</para>
96
97
</directive>
98
99
100
<directive name="ancient_browser_value">
101
<syntax><value>string</value></syntax>
102
<default>1</default>
103
<context>http</context>
104
<context>server</context>
105
<context>location</context>
106
107
<para>
108
设定变量<var>$ancient_browser</var>的值。
109
</para>
110
111
</directive>
112
113
114
<directive name="modern_browser">
115
<syntax><value>browser</value> <value>version</value></syntax>
116
<syntax><literal>unlisted</literal></syntax>
117
<default/>
118
<context>http</context>
119
<context>server</context>
120
<context>location</context>
121
122
<para>
123
指定一个版本,此版本及后续版本的浏览器都被认定为新式浏览器。
124
浏览器可以是下列之一: <literal>msie</literal>,
125
<literal>gecko</literal> (基于Mozilla),
126
<literal>opera</literal><literal>safari</literal>,
127
或者 <literal>konqueror</literal>
128
</para>
129
130
<para>
131
版本可被指定为以下形式:X, X.X, X.X.X, 或 X.X.X.X。
132
每一形式的最大值分别是4000, 4000.99, 4000.99.99, 和 4000.99.99.99。
133
</para>
134
135
<para>
136
浏览器既没有在<literal>modern_browser</literal>中列出,又没有在<link id="ancient_browser"/>
137
列出时,如果配置了特殊值<literal>unlisted</literal>,那么浏览器将被认定为新式浏览器,否则
138
认定为旧式浏览器。
139
如果请求头中没有<header>User-Agent</header>域,浏览器以没有列出对待。
140
</para>
141
142
</directive>
143
144
145
<directive name="modern_browser_value">
146
<syntax><value>string</value></syntax>
147
<default>1</default>
148
<context>http</context>
149
<context>server</context>
150
<context>location</context>
151
152
<para>
153
设定变量<var>$modern_browser</var>的值。
154
</para>
155
156
</directive>
157
158
</section>
159
160
</module>
161
162