MP3 or video files are playing instead of downloading

trover

Verified User
Joined
Nov 4, 2015
Messages
76
as title says, in some browsers like "Firefox" video/audio files are playing instead of downloading.
and also i know, users can disable this in browser: https://support.mozilla.org/en-US/questions/960216

but i need to prevent this from server side, is this possible?


also this can be done by .htaccess in Apache web-server:
Code:
<FilesMatch "\.(mov|mp4|mp3|jpg|pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>

but how can i use this code in nginx ? (i try http://winginx.com/en/htaccess --- http://www.anilcetin.com/ --- https://labs.gidix.de/nginx/ but no success to converting)

or is there any way to do this from ssh (web-server config file, php.ini ,mime.types ...) ?


Regards
 
Hello Dear Alex,

Thanks for reply,
which file i have to edit?
seems not possible in nginx-includes:

Code:
"if" directive is not allowed here in /etc/nginx/nginx-includes.conf
"add_header" directive is not allowed here in /etc/nginx/nginx-includes.conf
 
1. Did you check in what place you should add the block I posted?
You can see it here: https://gist.github.com/un33k/7119264

2. Then in Directadmin as admin go to -> Custom HTTPD Configurations
And find you domain. Click and open nginx section.

3. Use the proper token to insert the code:

+ CUSTOM1
+ CUSTOM2
+ CUSTOM3
+ CUSTOM4




p.s. Writing by memory. Just spend a time and make sure to find which one is the correct.
 
for sharing.
success with this code:
Code:
location ~ ^.*/(?P<request_basename>[^/]+\.(mp3))$ {
        add_header Content-Disposition 'attachment; filename="$request_basename"';
    }
 
Back
Top