配置nginx文件下载服务
模块:ngx_http_autoindex_module
常用指令:
autoindex on | off;
自动文件索引功能,默为off
Default: autoindex off;
Context: http, server, location
autoindex_exact_size on | off;
计算文件确切大小(单位bytes),off 显示大概大小(单位K、M),默认on
Default: autoindex_exact_size on;
Context: http, server, location
autoindex_localtime on | off ;
显示本机时间而非GMT(格林威治)时间,默认off
Default: autoindex_localtime off;
Context: http, server, location
autoindex_format html | xml | json | jsonp;
显示索引的页面文件风格,默认html
Default: autoindex_format html;
Context: http, server, location
This directive appeared in version 1.7.9
示例:
配置: [[email protected] conf.d]# vi /etc/nginx/conf.d/test.conf server { listen 80; server_name www.magedu.tech; root /opt/testdir/; limit_rate 2k; location / { limit_except GET { allow 10.0.0.126; deny all; } } location /download { autoindex on; #开启自动文件索引功能 autoindex_exact_size off; #关闭计算文件确切大小 autoindex_localtime on; # #autoindex_format json; #默认html limit_rate 100k; #限制下载速率 root /opt/; index index.html; #一般目录下不要有index.html auth_basic "admin area"; #基于basic的用户登录认证 auth_basic_user_file /etc/nginx/conf.d/.nginxpasswd; allow 10.0.0.1; #基于IP访问控制 deny all; } location /admin { auth_basic "admin area"; auth_basic_user_file /etc/nginx/conf.d/.nginxpasswd; } location /image { alias /opt/image/; try_files $uri $uri/tree.jpg =404; } error_page 404 =200 /404.html; location = /test.html { } } 创建下载目录 [[email protected] conf.d]# mkdir /opt/download [[email protected] conf.d]# ls 1.log 2.log 3.log 4.log messages
验证:
登录验证:
下载列表:
标签:站点,off,autoindex,共享资源,nginx,html,location,conf From: https://www.cnblogs.com/cnblogsfc/p/14498481.html