强制MP3文件下载而不是流媒体

时间:2016-08-06 07:40:38

标签: apache .htaccess nginx header content-disposition

我在根目录以外的其他目录中有一些mp3文件。

当用户点击指向mp3的链接时,不是下载,而是在大多数浏览器(主要是移动浏览器)中开始流式传输。

我尝试在.htaccess中添加以下代码,但没有运气

<FilesMatch "\.(?i:mp3)$">
  ForceType application/octet-stream
 Header set Content-Disposition attachment
</FilesMatch>

我的服务器是用apache和nginxcp(nginx管理员)构建的。任何人都可以帮助我吗?

编辑:以下是我的域vhost文件的已编辑文件。但是在我重建主机并重新启动nginx后,文件将更改为原始文件,代码“location~.mp3 $ {add_header Content-Disposition attachment;}”将消失。

server {
          error_log /var/log/nginx/vhost-error_log warn;
          listen 198.xxx.xx.xxx:80;
          listen [::]:80;
      server_name dl.xxxx.com www.dl.xxxx.com;
          access_log /usr/local/apache/domlogs/dl.xxxx.com-bytes_log bytes_log;
          access_log /usr/local/apache/domlogs/dl.xxxx.com combined;
          root /home/xxxx/public_html/download;
          #location / {
          location ~*.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
          expires 1M;
          try_files $uri @backend;
          }
          location / {
      error_page 405 = @backend;
          add_header X-Cache "HIT from Backend";
          proxy_pass 198.xxx.xx.xxx:8081;
          include proxy.inc;
      include microcache.inc;
          }
          location @backend {
          internal;
          proxy_pass http://198.xxx.xx.xxx:8081;
          include proxy.inc;
      include microcache.inc;
          }
          location ~ .*\.(php|jsp|cgi|pl|py)?$ {
          proxy_pass http://198.xxx.xx.xxx:8081;
          include proxy.inc;
      include microcache.inc;
          }
          location ~ /\.ht {
          deny all;
          }
          location ~ \.mp3$ { add_header Content-Disposition attachment; }
        }

0 个答案:

没有答案