Linux下nginx模块之
nginx_http_autoindex_module 可以提供下载功能
-
介绍
ngx_http_autoindex_module模块处理以斜杠字符(’ / ')x结尾的请求,并生成一个目录列表。 -
语法指令
-
默认情况: autoindex off
上下文: http, server, location
以location举例location / { autoindex on; #将目录里的内容显示出来 }
-
-
实际配置
-
进入nginx.conf文件
在location里面添加autoindex on;
保存退出并且reload nginx[root@#localhost conf]# nginx -s reload
-
返回上一级目录进入上图root路径
[root@#localhost conf]# cd .. [root@#localhost nginx1]# ls client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp [root@#localhost nginx1]# cd html/sc.com/ [root@#localhost sc.com]# ls index.html [root@#localhost sc.com]# cat index.html welcome to sc
由于html/sc.com/下只有index.html,所以请求会优先找到index.html,所以我们可以先将index.html删掉或改名[root@#localhost sc.com]# mv index.html index.html.back [root@#localhost sc.com]# ls index.html.back
再重新访问网站
-
-
验证测试
-
在sc.com目录下新建一个download目录
[root@#localhost sc.com]# mkdir download
[root@#localhost sc.com]# ls
download index.html.back -
进入download目录,在里面添加你想要提供下载的文件
[root@#localhost download]# ls boot.tar.gz
-
刷新页面进入download,点击文件即可下载
-