文章

content阶段

content阶段流程顺序:

1
concat -> random_index -> index -> auto_index -> static

index模块:

1
2
3
4
5
6
功能: 指定/访问时返回index文件的内容
模块: ngx_http_index_module

指令: index file ...;
默认: index index.html;
可以出现在: http server location

autoindex模块:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
功能: 当url以 / 结尾时,尝试以
        html/xml/json/jsonp
      等格式返回 root/alias 中指向目录的目录结构
模块: ngx_http_index_nodule
      默认编译进nginx
      可通过: --without-http_autoindex_module 取消

指令: authindex on | off;
默认: off
可以出现在: http server location

指令: autoindex_exact_size on | off;        # 只有autoindex_format默认返回html时有效,显示绝对路径还是相对路径
默认: on
可以出现在: http server location

指令: autoindex_format html | xml | json | jsonp;
默认: html
可以出现在: http server location

指令: autoindex_localtime on | off;
默认: off
可以出现在: http server location

concat模块: 由阿里巴巴提供的

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
功能: 当访问多个小文件时, 把他们合并到一次http请求中, 提高性能
模块: nginx_http_concat_module
        下载: https://github.com/alibaba/nginx-http-concat
        编译: --add-module=/opt/nginx-http-concat/
            下载之后的路径
        使用方法:
            在URI后加上 "??",后通过多个 "," 逗号分隔文件。
            如果还有参数,则在最后通过 "?" 添加参数
            eg: https://g.alicdn.com/??kissy/k/6.2.4/seed-min.js,kg/global-util/1.0.7/index-min.js,tb/tracker/4.3.5/index.js,kg/tb-nav/2.5.3/index-min.js,secdev/sufei_data/3.3.5/index.js

指令: concat on | off   #打开/关闭 concat
默认: concat off
可以出现在: http server location
    
指令: concat_delimiter: string      #将文件内容通过指定分隔符指定
默认: NONE
可以出现在: http, server, locatione

指令: concat_typesMIME types        #对哪些文件类型做合并
默认: concat types: text/css application/x-javascript
可以出现在: http, server, location

指令: concat_uniqueon | off      #是否对某一种类型还是多种类型文件进行合并
默认: concat_unique on
可以出现在: http, server, location

指令: concat_max_filesnumberp       #最多合并多少文件
默认: concat_max_files 10
可以出现在: http, server, location

指令: concat_ignore_file_erroron | off      #是否对不存在或者出现错误的文件进行忽略,直接进行下一个文件
默认: off
可以出现在: http, server, location
        
server {
    listen 15637;
    server_name www.fscloude.cn;

    root /var/www/test/;
    concat on;
    error_log logs/concat_test.log info;

    location / {
        concat_max_files 20;
        concat_types text/plain;    #只允许txt文件,其他文件访问会返回 400 bad request
        concat_unique on;
        concat_delimiter '||';
        concat_ignore_file_error on;
    }
}   
本文由作者按照 CC BY 4.0 进行授权