force file download in the browser, nginx server

You just need to return HTTP header Content-disposition:

location ~* /orig/(.+\.jpg)$ {
internal;
add_header Content-disposition "attachment; filename=$1";
}

Or
location ~* (.*\.pdf) {
types { application/octet-stream .pdf; }
default_type application/octet-stream;
}

Or full
server{
listen 80;
server_name test.localhost;
location / {
root /Users/vasil/test;
if ($request_filename !~* ^.*?\.(jpg)|(png)|(gif)){
add_header Content-Disposition: "$request_filename";
}
}
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注