nginx配置下载文件

1.nginx配置文件添加配置

location /download {
	root /data;
	add_header Content-Disposition: "attachment";
	add_header Content-Type application/octet-stream;
	autoindex off; # 开启目录浏览功能
	autoindex_exact_size off; # 关闭详细文件大小统计,让文件大小显示MBGB单位,默认为b
	autoindex_localtime on; # 开启以服务器本地时区显示文件修改日期
}

2.重启nginx

3.在/data/download 目录下创建要下载的文件 aa.txt

4.在浏览器输入:http://ip:prot/download/aa.txt