-
Notifications
You must be signed in to change notification settings - Fork 1
/
nginx.conf
513 lines (453 loc) · 14 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
server {
listen 8080;
root /usr/local/webapp;
access_log off;
error_log off;
default_type text/plain;
location ~* ^/api/dump(\/.*)?$ {
default_type text/html;
echo '<!DOCTYPE html>
<html lang="zh-CN" mip>
<head>
<meta charset="UTF-8">
<title>输出nginx全局变量</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="stylesheet" href="https://mipcache.bdstatic.com/static/v1/mip.css">
<link rel="canonical" href="https://echo.xuexb.com/api/dump/path">
<noscript>
<style mip-officialrelease>
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}
</style>
</noscript>
<style mip-custom>
table {
border-collapse: collapse;
border-spacing: 0;
display: block;
width: 100%;
overflow: auto;
word-break: normal;
word-break: keep-all;
}
td,th {
padding: 0;
}
th {
font-weight: bold;
}
th,
td {
padding: 6px 13px;
border: 1px solid #ddd;
}
tr {
background-color: #fff;
border-top: 1px solid #ccc;
}
tr:nth-child(2n) {
background-color: #f8f8f8;
}
</style>
</head>
<body>
<h1>输出nginx全局变量</h1>
<p>注意: 本站使用<code>nginx proxy</code>反向代理架设的Https, 所以可能有些参数还是Http的~</p>';
echo '<h3>服务器相关</h3>
<table>
<thead>
<tr>
<th>变量名</th>
<th>结果</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>nginx_version</td>
<td>$nginx_version</td>
<td>当前运行的nginx版本号</td>
</tr>
<tr>
<td>server_port</td>
<td>$server_port</td>
<td>服务器端口</td>
</tr>
<tr>
<td>server_addr</td>
<td>$server_addr</td>
<td>服务器端地址,需要注意的是:为了避免访问linux系统内核,应将ip地址提前设置在配置文件中</td>
</tr>
<tr>
<td>server_name</td>
<td>$server_name</td>
<td>服务器名</td>
</tr>
<tr>
<td>server_protocol</td>
<td>$server_protocol</td>
<td>服务器的HTTP版本, 通常为 “HTTP/1.0” 或 “HTTP/1.1”</td>
</tr>
<tr>
<td>status</td>
<td>$status</td>
<td>HTTP响应代码</td>
</tr>
<tr>
<td>time_iso8601</td>
<td>$time_iso8601</td>
<td>服务器时间的ISO 8610格式 (1.3.12, 1.2.7)</td>
</tr>
<tr>
<td>time_local</td>
<td>$time_local</td>
<td>服务器时间(LOG Format 格式) (1.3.12, 1.2.7)</td>
</tr>
<tr>
<td>document_root</td>
<td>$document_root</td>
<td>当前请求的文档根目录或别名</td>
</tr>
<tr>
<td>request_filename</td>
<td>$request_filename</td>
<td>当前连接请求的文件路径,由root或alias指令与URI请求生成</td>
</tr>
<tr>
<td>request_completion</td>
<td>$request_completion</td>
<td>如果请求成功,值为”OK”,如果请求未完成或者请求不是一个范围请求的最后一部分,则为空</td>
</tr>
<tr>
<td>pid</td>
<td>$pid</td>
<td>工作进程的PID</td>
</tr>
<tr>
<td>msec</td>
<td>$msec</td>
<td>当前的Unix时间戳 (1.3.9, 1.2.6)</td>
</tr>
<tr>
<td>limit_rate</td>
<td>$limit_rate</td>
<td>用于设置响应的速度限制,详见 limit_rate</td>
</tr>
<tr>
<td>pipe</td>
<td>$pipe</td>
<td>如果请求来自管道通信,值为“p”,否则为“.” (1.3.12, 1.2.7)</td>
</tr>
<tr>
<td>connection_requests</td>
<td>$connection_requests</td>
<td>TCP连接当前的请求数量 (1.3.8, 1.2.5)</td>
</tr>
<tr>
<td>connection</td>
<td>$connection</td>
<td>TCP连接的序列号 (1.3.8, 1.2.5)</td>
</tr>
<tr>
<td>realpath_root</td>
<td>$realpath_root</td>
<td>当前请求的文档根目录或别名的真实路径,会将所有符号连接转换为真实路径</td>
</tr>
</tbody>
</table>';
echo '<h3>客户端相关</h3>
<table>
<thead>
<tr>
<th>变量名</th>
<th>结果</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>host</td>
<td>$host</td>
<td>优先级如下:HTTP请求行的主机名>”HOST”请求头字段>符合请求的服务器名</td>
</tr>
<tr>
<td>hostname</td>
<td>$hostname</td>
<td>主机名</td>
</tr>
<tr>
<td>remote_port</td>
<td>$remote_port</td>
<td>客户端端口</td>
</tr>
<tr>
<td>remote_user</td>
<td>$remote_user</td>
<td>用于HTTP基础认证服务的用户名</td>
</tr>
<tr>
<td>request</td>
<td>$request</td>
<td>代表客户端的请求地址</td>
</tr>
<tr>
<td>remote_addr</td>
<td>$remote_addr</td>
<td>客户端地址</td>
</tr>
<tr>
<td>request_body</td>
<td>$request_body</td>
<td>客户端的请求主体, 此变量可在location中使用,将请求主体通过proxy_pass, fastcgi_pass, uwsgi_pass, 和 scgi_pass传递给下一级的代理服务器</td>
</tr>
<tr>
<td>request_body_file</td>
<td>$request_body_file</td>
<td>将客户端请求主体保存在临时文件中文件处理结束后,此文件需删除如果需要之一开启此功能,需要设置client_body_in_file_only如果将次文件传递给后端的代理服务器,需要禁用request body,即设置proxy_pass_request_body off,fastcgi_pass_request_body off, uwsgi_pass_request_body off, or scgi_pass_request_body off </td>
</tr>
<tr>
<td>proxy_protocol_addr</td>
<td>$proxy_protocol_addr</td>
<td>获取代理访问服务器的客户端地址,如果是直接访问,该值为空字符串(1.5.12)</td>
</tr>
<tr>
<td>http_名称</td>
<td>http_accept_language -> $http_accept_language</td>
<td>匹配任意请求头字段; 变量名中的后半部分“name”可以替换成任意请求头字段,如在配置文件中需要获取http请求头:“Accept-Language”,那么将“-”替换为下划线,大写字母替换为小写,形如:http_accept_language即可</td>
</tr>
<tr>
<td>bytes_sent</td>
<td>$bytes_sent</td>
<td>传输给客户端的字节数 (1.3.8, 1.2.5)</td>
</tr>
<tr>
<td>body_bytes_sent</td>
<td>$body_bytes_sent</td>
<td>传输给客户端的字节数,响应头不计算在内;这个变量和Apache的mod_log_config模块中的“%B”参数保持兼容</td>
</tr>
</tbody>
</table>';
echo '<h3>客户端相关 - request headers</h3>
<table>
<thead>
<tr>
<th>变量名</th>
<th>结果</th>
</tr>
</thead>
<tbody>
<tr>
<td>http_accept</td>
<td>$http_accept</td>
</tr>
<tr>
<td>http_accept_encoding</td>
<td>$http_accept_encoding</td>
</tr>
<tr>
<td>http_accept_language</td>
<td>$http_accept_language</td>
</tr>
<tr>
<td>http_cache_control</td>
<td>$http_cache_control</td>
</tr>
<tr>
<td>http_connection</td>
<td>$http_connection</td>
</tr>
<tr>
<td>http_cookie</td>
<td>$http_cookie</td>
</tr>
<tr>
<td>http_host</td>
<td>$http_host</td>
</tr>
<tr>
<td>http_origin</td>
<td>$http_origin</td>
</tr>
<tr>
<td>http_referer</td>
<td>$http_referer</td>
</tr>
<tr>
<td>http_pragma</td>
<td>$http_pragma</td>
</tr>
<tr>
<td>http_upgrade_insecure_requests</td>
<td>$http_upgrade_insecure_requests</td>
</tr>
<tr>
<td>http_user_agent</td>
<td>$http_user_agent</td>
</tr>
<tr>
<td>http_x_requested_with</td>
<td>$http_x_requested_with</td>
</tr>
<tr>
<td>http_x_forwarded_for</td>
<td>$http_x_forwarded_for</td>
</tr>
<tr>
<td>http_x_forwarded_proto</td>
<td>$http_x_forwarded_proto</td>
</tr>
</tbody>
</table>';
echo '<h3>链接相关</h3>
<table>
<thead>
<tr>
<th>变量名</th>
<th>结果</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>scheme</td>
<td>$scheme</td>
<td>请求使用的Web协议, “http” 或 “https”</td>
</tr>
<tr>
<td>document_uri</td>
<td>$document_uri</td>
<td>同 uri</td>
</tr>
<tr>
<td>request_uri</td>
<td>$request_uri</td>
<td>这个变量等于包含一些客户端请求参数的原始URI,它无法修改,请查看$uri更改或重写URI,不包含主机名,例如:”/cnphp/test.php?arg=freemouse”</td>
</tr>
<tr>
<td>uri</td>
<td>$uri</td>
<td>请求中的当前URI(不带请求参数,参数位于args),可以不同于浏览器传递的request_uri的值,它可以通过内部重定向,或者使用index指令进行修改,$uri不包含主机名,如”/foo/bar.html”</td>
</tr>
<tr>
<td>request_method</td>
<td>$request_method</td>
<td>HTTP请求方法,通常为“GET”或“POST”</td>
</tr>
<tr>
<td>request_time</td>
<td>$request_time</td>
<td>处理客户端请求使用的时间 (1.3.9, 1.2.6); 从读取客户端的第一个字节开始计时</td>
</tr>
<tr>
<td>request_length</td>
<td>$request_length</td>
<td>请求的长度 (包括请求的地址, http请求头和请求主体) (1.3.12, 1.2.7)</td>
</tr>
<tr>
<td>query_string</td>
<td>$query_string</td>
<td>同args</td>
</tr>
<tr>
<td>args</td>
<td>$args</td>
<td>请求中的参数值</td>
</tr>
<tr>
<td>arg_参数名</td>
<td>arg_a => $arg_a</td>
<td>请求中的的参数名,即“?”后面的arg_name=arg_value形式的arg_name</td>
</tr>
<tr>
<td>is_args</td>
<td>$is_args</td>
<td>如果请求中有参数,值为“?”,否则为空字符串</td>
</tr>
<tr>
<td>https</td>
<td>$https</td>
<td>如果开启了SSL安全模式,值为“on”,否则为空字符串</td>
</tr>
</tbody>
</table>';
echo '<script src="https://mipcache.bdstatic.com/static/v1/mip.js"></script></body></html>';
}
# 简单的hello, world!
location = /api/hello {
echo "hello, world!";
}
# 反向代理添加前置、后置内容
location = /api/proxy_before_after {
echo_before_body echo_before_body;
echo_before_body echo_before_body;
proxy_pass http://127.0.0.1:8080/api/hello;
echo_after_body echo_after_body;
echo_after_body echo_after_body;
}
# sleep测试
location ~* ^/api/sleep(\/\d*\/?)?$ {
echo "{";
echo " request_uri=$request_uri";
set $time 2;
if ($uri ~* ^(.+?)/(\d+)/?$) {
set $time $2;
}
echo_sleep $time;
echo " time=$time";
echo "}";
}
# 异步调用
location = /api/location_async {
echo location_async;
# 重置时间
echo_reset_timer;
# subrequests in parallel
echo_location_async /api/sleep/1;
echo_location_async /api/sleep/2;
echo "took $echo_timer_elapsed sec for total.";
}
# 同步调用
location = /api/location {
echo location;
# 重置时间
echo_reset_timer;
# subrequests in parallel
echo_location /api/sleep/1;
echo_location /api/sleep/2;
echo "took $echo_timer_elapsed sec for total.";
}
# 重复
location = /api/duplicate {
echo_duplicate 3 "hello, world";
}
# 分隔 ?list=aa,bb
location = /api/split {
echo_foreach_split ',' $arg_list;
echo "item: $echo_it";
echo_end;
}
# 模拟combo
location = /api/combo {
echo_foreach_split ',' $query_string;
echo "/* combo: $echo_it */";
echo_location_async $echo_it;
echo;
echo_end;
}
# 输出内容
location ~* ^/api/echo(\/[^\/]*?\/?)?$ {
set $str 'null';
if ($uri ~* ^/api/echo/([^\/]+)/?$) {
set $str $1;
}
echo $str;
}
location ^~ /api/cache {
echo "请查看 response headers, 由于有缓存请添加随时数来查看最新效果, 如: ?r=时间缀";
}
}