server {
listen 8080;
server_name 192.168.99.66;
location = /Test.apk {
autoindex on;
}
location = /Test.apk {
alias /data/wwwroot/apk/Test.apk;
autoindex on;
}
location = /apk {
alias /data/wwwroot/apk;
autoindex_exact_size off;
autoindex on;
}
}
#当你想让nginx作为文件下载服务器存在时,需要开启nginx目录展示功能
server {
location download {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
autoindex_format html;
}
}
#autoindex_exact_size: 为on(默认)时显示文件的确切大小,单位是byte;改为off显示文件大概大小,单位KB或MB或GB,autoindex_format为html格式时有效
#autoindex_localtime: 为off(默认)时显示的文件时间为GMT时间;改为on后,显示的文件时间为服务器时间,autoindex_format为html格式时有效
#autoindex_format:以网页的风格展示目录内容。该属性在1.7.9及以上适用
#默认当访问列出的txt等文件时会在浏览器上显示文件的内容,如果你想让浏览器直接下载,可以加上下边的配置
if ($request_filename ~* ^.*?\.(txt|pdf|jpg|png)$) {
add_header Content-Disposition 'attachment;';
}