Nginx-模块-ngx_http_autoindex_module【目录索引】
1、基础
1.1、作用
当ngx_http_index_module模块找不到索引文件时,通常会将请求传递给ngx_http_autoindex_module模块。 ngx_http_autoindex_module模块处理以斜杠字符(')结尾的请求,并生成目录列表。
1.2、指令介绍
1.2.1、autoindex-是否显示目录
# 启用或禁用目录列表输出,on开启,of关闭。 Syntax: autoindex on | off; Default: autoindex off; Context: http, server, location
1.2.2、autoindex_exact_size-是否显示文件大小
# 指定是否应在目录列表中输出确切的文件大小, on显示字节,off显示大概单位。 Syntax: autoindex_exact_size on | off; Default: autoindex_exact_size on; Context: http, server, location
1.2.3、autoindex_localtime-显示时间的设置
#指定目录列表中的时间是应以本地时区还是UTC输出。on本地时区,off UTC时间。 Syntax: autoindex_localtime on | off; Default: autoindex_localtime off; Context: http, server, location
2、实战
2.1、当前项目共享目录出来显示
2.1.1、项目的结构
]# tree /opt/project1/ /opt/project1/ ├── cyc │ └── 1.txt └── index.html
2.1.2、配置nginx
cat >/etc/nginx/conf.d/80.cyc.com.conf <<'EOF' server{ listen 80; server_name project1.cyc.com; charset utf-8; # 防止显示乱码 autoindex on; autoindex_exact_size off; autoindex_localtime on; location / { root /opt/project1; index index.html; } } EOF
2.1.3、重新加载nginx
systemctl reload nginx
2.1.4、访问测试
2.2、搭建yum镜像仓库
2.2.1、挂载镜像盘
mkdir /mnt/cdrom mount /dev/cdrom /mnt/cdrom
2.2.2、项目目录结构
]# ll /mnt/cdrom -rw-r--r-- 3 root root 14 Oct 30 2020 CentOS_BuildTag drwxr-xr-x 3 root root 2048 Oct 27 2020 EFI -rw-rw-r-- 21 root root 227 Aug 30 2017 EULA -rw-rw-r-- 21 root root 18009 Dec 10 2015 GPL drwxr-xr-x 3 root root 2048 Oct 27 2020 images drwxr-xr-x 2 root root 2048 Nov 3 2020 isolinux drwxr-xr-x 2 root root 2048 Oct 27 2020 LiveOS drwxr-xr-x 2 root root 673792 Nov 4 2020 Packages drwxr-xr-x 2 root root 4096 Nov 4 2020 repodata -rw-rw-r-- 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7 -rw-rw-r-- 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r-- 1 root root 2883 Nov 4 2020 TRANS.TBL
2.2.3、配置nginx
cat >/etc/nginx/conf.d/mirror.cyc.com.conf <<'EOF' server{ listen 80; server_name mirror.cyc.com; charset utf-8; root /mnt/; location /cdrom { autoindex on; autoindex_exact_size off; autoindex_localtime on; } location / { index index.html; } } EOF
2.2.4、重新加载nginx
systemctl reload nginx
2.2.5、访问测试