Nginx İle Force Download

January 20, 2020

Browserlar akıllandıkça, farklı dosya uzantıları için default aksiyonu değişiyor. Eskiden mp4 tipindeki bir uzantı gördüğü zaman default olarak indirmeye çalışırdı. Şimdilerde ise varsayılan olarak oynatmayı deniyor. Keza pdf için de aynı şey geçerli.

Statik dosyalara content-disposition header ı eklemek ne sürebilir? Ben de sizin gibi 5 dakika alacağını düşünmüştüm ancak yarım saat nginx dokumantasyonu okuduktan sonra fikrim değişti.

Aşağıdaki nginx konfigurasyonu bir subdirectory içindeki dosyaları listeliyor ve seçtiğiniz dosyalar mp4 veya pdf ise Content-Disposition header ı ekliyor.

Nginx Konfigurasyonu

1
2
3
4
5
6
7
8
location /bindaddress {

    # force it to download
    if ($request_filename ~ "^.*/(.+\.(mp4|pdf))$"){
        set $fname $1;
        add_header Content-Disposition 'attachment; filename="$fname"';
    }
}

hidden

The Review Is the Action Item

2024/05/30The Review Is the Action ItemI like to consider running an incident review to be its own action item. Other follow-ups emerging from it are a plus, but the point is to learn from incidents, and the review gives room for that to happen.This is no…

via Ferd.ca

Finding a New Software Developer Job

For the first time ever, I was laid off, and had to find a new software developer job. I managed to find a new one, but it took longer than I thought, and it was a lot of work. I … Continue reading →

via Henrik Warne's blog

HOWTO: Change your behavior

In theory, behavior change should be easy. At first glance, it seems like you control your behavior. So, if you desire different behavior, why doesn’t your behavior change as instantly as your desire to change it? In short, lasting change of habitual behavio…

via Matt Might's blog