Nginx配置列出目录做为资源下载服务器

2022-07-18T01:42:00

效果图

列出目录 autoindex配置

Nginx默认是不允许列出整个目录的。如需此功能,打开nginx.conf文件,在location,server 或 http段中加入如下参数:这个功能我们可以做一个资源下载站。

/file代表访问路径,比如以下配置相当于/data/www//file 列出目录下所有资源
ps:注意,需要先创建好对应的目录,要不然会出现访问会出现404状态

#列出目录 autoindex
location ^~ /file {
    root   /data/www;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
    charset utf-8,gbk;
}

  • autoindex on;运行列出目录内容。另外两个参数最好也加上去。
  • autoindex_exact_size off; 默认为on,显示出文件的确切大小,单位是bytes。改为off后,显示出文件的大概大小,单位是kB或者MB或者GB。
  • autoindex_localtime on; 默认为off,显示的文件时间为GMT时间。改为on后,显示的文件时间为文件的服务器时间。

配置完成后,重启nginx

重启nginx

/usr/local/nginx/sbin/nginx -s reopen

停止nginx

/usr/local/nginx/sbin/nginx -s stop

启动nginx

/usr/local/nginx/sbin/nginx

访问127.0.0.1/file
页面显示

服务器目录

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »