【问题标题】:nginx: how to avoid forced downloads in all wav files?nginx:如何避免强制下载所有 wav 文件?
【发布时间】:2015-06-11 11:23:04
【问题描述】:

这是我的 nginx 站点配置文件:

server {
  listen 81;

  root /path/;
  index index.php index.html index.htm;

  location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
    access_log off;
    expires 30d;
  }

  location /path/to/sounds {
    add_header Content-Disposition "inline";
  }

  location / {

    if (!-e $request_filename) {
      rewrite ^(.+)$ /index.php?q=$1 last;
    }

  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass 127.0.0.1:9001;
    fastcgi_index index.php;
    include fastcgi_params;
  }

}

我在特定文件夹中有几个 wav 文件:0001.wav、0002.wav、a.wav、b.wav...

页面应该播放这些文件,但在某些情况下(以字母开头的文件,例如 a.wav、b.wav)Chrome 正在下载它们。这很奇怪。

对于 a.wav 文件,Chrome 控制台日志显示:

Resource interpreted as Document but transferred with MIME type application/octet-stream:

虽然相同的控制台日志显示:

Resource interpreted as Document but transferred with MIME type audio/x-wav

我在同一台服务器上安装了 Apache。它适用于所有文件:

Resource interpreted as Document but transferred with MIME type audio/x-wav

我已经在/etc/nginx/mime.types中添加了:

 audio/x-wav                             wav;

另外,我也换了

 location /path/to/sounds { 

 location ~ \.wav$ {

这里有什么问题?

【问题讨论】:

    标签: audio nginx mime-types


    【解决方案1】:

    已解决:

    我添加到我的 mime.types 文件中:

     audio/x-wav                wav;
    

    在我的 nginx 配置中:

    location ~ \.wav$ {
      add_header Content-Disposition "inline";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多