File Downloads with reverse proxy

Callum Scott scott.callum at
Fri Mar 15 14:17:01 UTC 2019

Hi All,

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/(.*)  {
    set $bucket           '';
    set $aws_access       'my_aws_access_key';
    set $aws_secret       'my_aws_secret_key';
    set $url_full         "$1";
    set_by_lua $now       "return ngx.cookie_time(ngx.time())";
    set $string_to_sign
    set_hmac_sha1          $aws_signature $aws_secret $string_to_sign;
    set_encode_base64      $aws_signature $aws_signature;

    resolver      valid=300s;
    resolver_timeout       10s;

    proxy_http_version     1.1;
    proxy_set_header       Host $;
    proxy_set_header       x-amz-date $now;
    proxy_set_header       Authorization "AWS $aws_access:$aws_signature";
    proxy_buffering        off;
    proxy_intercept_errors on;

    rewrite .* /$url_full break;

    more_set_headers 'Access-Control-Allow-Origin: $cors_header' 'Vary:

    proxy_pass   ;


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";

The equivelent apache config that works is

# Add headers to force download if required
RewriteCond %{REQUEST_URI} \.mp4$
RewriteCond %{QUERY_STRING} ^download$
RewriteRule ^ "-" [E=dwn: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?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list