Linux下nginx模块之ngx_http_autoindex_module

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,点击文件即可下载
      在这里插入图片描述

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值