File tree Expand file tree Collapse file tree 2 files changed +84
-1
lines changed Expand file tree Collapse file tree 2 files changed +84
-1
lines changed Original file line number Diff line number Diff line change
1
+ ## 08、文件列表
2
+
3
+ ### 1、何为文件列表
4
+
5
+ 如下图:
6
+
7
+ <img src =' ./img/08_01.png ' />
8
+
9
+ 简单来说,就是用户可以下载一些你想给他下载的文件,我们有时候会遇见这些需求。
10
+
11
+ 这些就是 【文件列表】。
12
+
13
+ ### 2、如何配置文件列表
14
+
15
+ 核心属性是 location 配置里的 autoindex
16
+
17
+ 简单来说,location 配置路径,autoindex 值为 on 的时候,则打开文件列表模式。
18
+
19
+ 然后配置下载路径,以及设置文件所在目录即可。
20
+
21
+ ```
22
+ location ^~ 用户访问的路径 {
23
+ alias 本地文件存储目录;
24
+ autoindex on;
25
+ }
26
+ ```
27
+
28
+ <b >举个例子:</b >
29
+
30
+ 为了方便理解,举例来说,我希望用户访问 `` http://a.test.com/files/ `` 目录时,可以访问到本地的 `` /usr/local/nginx/files/ `` 目录里的文件。
31
+
32
+ ```
33
+ location ^~ /files/ {
34
+ alias /usr/local/nginx/files/;
35
+ autoindex on;
36
+ }
37
+ ```
38
+
39
+ <b >属性分析:</b >
40
+
41
+ * `` location `` :表示路径匹配设置,固定不变。
42
+ * `` ^~ `` :表示如果该符号后面的字符是最佳匹配,采用该规则,不再进行后续的查找。我们在配置这个功能的时候,通常这么配置就可以了。
43
+ * `` /files/ `` :表示用户访问路径 `` /files/ `` 的时候,符合这条匹配规则,被这条配置处理;
44
+ * `` alias `` :和 root 类似,但效果有所不同:
45
+ * alias :指访问 `` http://a.test.com/files/ `` 时,实际访问的是 `` /usr/local/nginx/files/ `` 目录;
46
+ * root :这里指后面不变,访问 `` http://a.test.com/files/ `` 时,实际访问的是 `` /usr/local/nginx/files/files/ `` 目录;
47
+ * 即使用 root 时,本地目录会将 location 路径 `` /files/ `` 加到本地目录后面;
48
+ * 而 alias 时,本地目录会无视 location 路径;
49
+ * `` /usr/local/nginx/files/ `` :本地目录;
50
+ * `` autoindex `` :默认为 off 不打开,未打开的时候,将不能以文件目录的形式访问页面;
51
+
52
+ <b >直接在某个目录打开文件功能:</b >
53
+
54
+ ```
55
+ location /files/ {
56
+ root html;
57
+ autoindex on;
58
+ }
59
+ ```
60
+
61
+ * 访问 /files/ 目录时,以文件列表的形式来访问目录;
62
+
63
+
64
+ ###3 、指令配置
65
+
66
+ <b >autoindex_exact_size [ on|off] </b >
67
+
68
+ * 默认值为 on,显示详细的大小,比如 2188060 ;
69
+ * off 时,文件大小则以 B(省略)、K、M等单位来显示(分别表示B、KB、MB等);
70
+
71
+ <b >autoindex_localtime [ on|off] </b >
72
+
73
+ * 开启以本地时间来显示文件时间的功能,默认为关;
74
+ * 即默认显示的是 服务器时间的 文件时间;
75
+ * on 时,显示文件时间为 本地时间;
76
+
77
+
78
+ ###4 、参考博客
79
+
80
+ * https://stackoverflow.com/questions/10631933/nginx-static-file-serving-confusion-with-root-alias (讲了 alias 和 root 的区别)
81
+ *
Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ http://www.nginx.cn/doc/
30
30
31
31
<a href =' https://github.com/qq20004604/nginx-demo/blob/master/06、一个nginx服务器为多个域名服务.md ' >06、一个nginx服务器为多个域名服务</a >
32
32
33
- <a href =' https://github.com/qq20004604/nginx-demo/blob/master/07、日志 ' >07、日志</a >
33
+ <a href =' https://github.com/qq20004604/nginx-demo/blob/master/07、日志.md ' >07、日志</a >
34
+
35
+ <a href =' https://github.com/qq20004604/nginx-demo/blob/master/08、文件列表.md ' >08、文件列表</a >
34
36
35
37
36
38
### xx、主进程pid
You can’t perform that action at this time.
0 commit comments