Ahli Kompie

Nginx Canonical dan Force Download

Untuk membuat sebuah file menjadi canonical ke domain lainnya dan force download semua isi file (misalkan untuk keperluan download center), tambahkan baris berikut ke nginx config:

Pertama chmod dulu file configurasi nginx, kalau di VestaCP begini caranya:

chmod 777 /home/username/conf/web/*.conf

Force Download dan Canonical Pada Seluruh Folder

Tambahkan entry ini pada entry virtualhost dalam nginx.conf. Gunakan file explorer pada MobaXterm atau WinSCP agar mudah melakukan edit sebagai root.

location /files/ { 
	default_type application/octet-stream;
	add_header Content-Disposition "attachment";
	add_header Link "<http://example.com$request_uri>; rel='canonical'";
}

Force Download dan Canonical Pada Folder Tertentu

Tambahkan entry ini pada entry virtualhost dalam nginx.conf. Gunakan file explorer pada MobaXterm atau WinSCP agar mudah melakukan edit sebagai root.

Untuk force download hanya dari folder files dan semuanya diberikan HTTP header canonical, gunakan berikut:

location /files/ { 
	default_type application/octet-stream;
	add_header Content-Disposition "attachment";
	add_header Link "<http://example.com$request_uri>; rel='canonical'";
}

Penempatannya ditaruh setelah lokasi root (/) :

Atau bisa juga sebelum lokasi root (/):

Bisa juga diberi alias, seperti begini:

location /files/ {
    alias /var/openStuff/file/;
    default_type application/octet-stream;
    add_header Content-Disposition "attachment";
    add_header Link "<http://example.com$request_uri>; rel='canonical'";
 }

Semua request ke example.com/files/x will akan dilayani dari folder /var/openStuffs/file dan akan mencari file x dan akan memaksa browser untuk mendownload filenya

Kalau file pathnya di browser /files/stuff/things.txt akan dilayani oleh server dari /var/openStuff/file/sstuff/things.txt

Referensi:

http://stackoverflow.com/a/36815844

https://stackoverflow.com/questions/9054354/how-to-force-file-download-in-the-browser-nginx-server

https://ahlikompie.com/2235-add-nginx-canonical-header-di-vesta-cp.html


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *