Skip to content

Instantly share code, notes, and snippets.

@tung1404
Forked from un33k/nginx.conf
Created May 22, 2025 09:14
Show Gist options
  • Save tung1404/3a55f94c3885a2a136d15d00bd9992dd to your computer and use it in GitHub Desktop.
Save tung1404/3a55f94c3885a2a136d15d00bd9992dd to your computer and use it in GitHub Desktop.
Enable Nginx to send Content-Dispositions on specific files
server {
listen *:80;
server_name www.example.com;
rewrite ^(.*) http://example.com $1 permanent;
}
server {
listen *:80;
server_name example.com;
# Static directory
location /data/ {
autoindex on;
alias /data/;
expires 30d;
if ( $request_filename ~ "^.*/(.+\.(zip|tgz|iso|gz))$" ){
set $fname $1;
add_header Content-Disposition 'attachment; filename="$fname"';
}
}
root /srv/www/example.com;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/errors.log;
# Redirect server error pages to the static page /50x.html
error_page 500 502 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment