audio - nginx:如何避免强制下载所有 wav 文件?

标签 audio nginx mime-types

这是我的 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$ {

这里出了什么问题?

最佳答案

已解决:

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

 audio/x-wav                wav;

在我的 nginx 配置中:

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

关于audio - nginx:如何避免强制下载所有 wav 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30779412/

相关文章:

nginx - 高负载下502网关错误(nginx/php-fpm)

Nginx CSP frame-src 被忽略

android - 如何避免 Intent 过滤器中的 */* mime 类型

python - 奇异果和游戏中的声音:游戏更新循环等待声音完成,然后继续[奇异果中使用SoundLoader的FPS问题]

android - 音轨setVolume-最小值

python - 如何从python中的mathplot识别某个y值的所有x坐标值

javascript - 如何在 MultipartFormData 的 REST API 中使用内容类型为 message/rfc822 的文件?

c - 使用 taglib 库函数中的 C 语言的音频文件的属性

正则表达式截断 nginx 上的字符串

php - PHP 生成的 JSON 文件具有 application/octet-stream mime 类型