File Downloads with reverse proxy

Francis Daly francis at daoine.org
Sat Mar 16 09:56:15 UTC 2019


On Fri, Mar 15, 2019 at 02:17:01PM +0000, Callum Scott wrote:

Hi there,

> I am having difficulty forcing downloads of mp4 files with a ?download
> query in the url.
> 
> I am proxying files from an s3 bucket like this
> 
>   location ~* ^/myvideo/content/(.*)  {
...
>     proxy_pass             http://s3.amazonaws.com;
>   }
> 
> 
> and have another location section like this
> 
>   location ~* (.*\.mp4\?download) {
>     autoindex off;
>     expires 365d;
>     add_header Pragma public;
>     add_header Cache-Control "public";
> 
>     if ($arg_dl = "1") {
>         add_header Content-disposition "attachment; filename=$1";
>     }
>   }

> I was expecting the video to download in this case, however it is just
> streamed instead as it would be without the ?download query.
> 
> Can somone please suggest where I am going wrong?

* one request is handled in one location, so if your second location is
used, the proxy_pass from the first is not used. See http://nginx.org/r/location

* $arg_dl is the value of the "dl" argument. Possibly you want
$arg_download, or 'if ($args = "download")'. See http://nginx.org/r/$arg_

* nginx does not use the query string (? part) in choosing which location
to use. So your second location will not match any "normal" requests.

I'm not certain what your overall requirements are; but possibly the
simplest config would be not to configure things specially, and just
let the client decide what they want to download by using their "save
link as" feature.

I hope this points you in the right direction.

Cheers,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list