nginx开启列目录 作为文件下载服务器
server {
location download {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
autoindex_exact_size:
为on(默认)时显示文件的确切大小,单位是byte;
为off显示文件大概大小,单位KB或MB或GB
autoindex_localtime:
为off(默认)时显示的文件时间为GMT时间;
为on后,显示的文件时间为服务器时间
默认当访问列出的txt等文件时会在浏览器上显示文件的内容
如果想让浏览器直接下载,加上下边的配置
if ($request_filename ~* ^.*?\.(txt|pdf|jpg|png)$) {
add_header Content-Disposition 'attachment';
}