文件下载
server {
listen 80;
server_name localhost;
location ^~ /download/ {
alias /home/webhtml/;
# 判断文件的后缀。以及提供下载功能。
if ($request_filename ~* ^.*?\.(html|doc|pdf|zip|docx|txt)$) {
add_header Content-Disposition attachment;
add_header Content-Type application/octet-stream;
}
sendfile on; # 开启高效文件传输模式
autoindex on; # 开启目录文件列表
autoindex_exact_size on; # 显示出文件的确切大小,单位是bytes
autoindex_localtime on; # 显示的文件时间为文件的服务器时间
charset utf-8,gbk; # 避免中文乱码
}
参考
https://blog.csdn.net/chj_1224365967/article/details/113632856