Nginx实现MP3的播放和下载

参考:

http://segmentfault.com/blog/p_chou/1190000000437323?utm_source=tuicool

http://www.netingcn.com/nginx-add-header.html

http://nginx.org/cn/docs/http/ngx_http_rewrite_module.html

项目需要MP3下载的功能,GOOGLE了几篇文章,参考实现了这个功能,用时大概3个番茄钟,了解了Nginx内置变量和正则判断请求URL的方法。

需求:

打开URL:http://localhost/a_short_song.mp3 ,在线播放音乐

打开URL:http://localhost/a_short_song.mp3?download=a.mp3 实现MP3下载,并重命名文件名为指定参数: a.mp3

Nginx配置文件中的配置代码如下:

        location / {            
			index index.html index.php; 
			if ($arg_download){ 
				add_header Content-Disposition "attachment; filename=$arg_download";				 
			} 
        }

问题:中文文件名时有问题,如http://localhost/a_short_song.mp3?download=张三.mp3时,下载的文件名称为:%E5%BC%A0%E4%B8%89.mp3,有待解决一下。

原文地址:https://www.cnblogs.com/laohehexiaohe/p/4286841.html