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