nginx: how to avoid forced downloads in all wav files?

2.9k views Asked by At

This is my nginx site config file:

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;
  }

}

I have several wav files in a specific folder: 0001.wav, 0002.wav, a.wav, b.wav...

A page should play these files but in some cases (files starting with letters, such as a.wav, b.wav) Chrome is downloading them. This is very strange.

For the a.wav file, the Chrome console log says:

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

while the same console log says:

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

I have Apache in the same server. It works fine for all files:

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

I have already added in /etc/nginx/mime.types:

 audio/x-wav                             wav;

In addition, I also replaced

 location /path/to/sounds { 

to

 location ~ \.wav$ {

What is wrong here?

1

There are 1 answers

0
leozera On

SOLVED:

I added to my mime.types file:

 audio/x-wav                wav;

In my nginx config:

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