1.windows
2.路径如D:/im-az/server/download
下面有各种文件
3.配置
location /download {
root D:/im-az/server;
autoindex on; # 开启目录浏览功能
autoindex_format html; #以html风格将目录展示在浏览器中
autoindex_exact_size off; #切换为 off 后,以可读的方式显示文件大小,单位为 KB、MB 或者 GB
autoindex_localtime on; #以服务器的文件时间作为显示的时间
#符合条件,直接下载
if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
add_header Content-Disposition attachment;
}
}

该配置文件描述了在Windows环境下,针对D:/im-az/server/download目录,如何使用Nginx开启目录浏览功能,以HTML格式展示文件,并以服务器本地时间显示文件时间。同时,当请求的文件扩展名匹配特定类型(如txt,doc,pdf等)时,自动设置Content-Disposition为attachment,促使文件直接下载。
2814

被折叠的 条评论
为什么被折叠?



