Welcome! Log In Create A New Profile

Advanced

File Downloads with reverse proxy

Callum Scott
March 15, 2019 10:18AM
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 'mys3buket.domain.com';
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
"$request_method\n\n\n\nx-amz-date:${now}\n/$bucket/$url_full";
set_hmac_sha1 $aws_signature $aws_secret $string_to_sign;
set_encode_base64 $aws_signature $aws_signature;

resolver 172.31.0.2 valid=300s;
resolver_timeout 10s;

proxy_http_version 1.1;
proxy_set_header Host $bucket.s3.amazonaws.com;
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:
Origin';

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

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?

Regards

--
Callum
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

File Downloads with reverse proxy

Callum Scott March 15, 2019 10:18AM

Re: File Downloads with reverse proxy

Francis Daly March 16, 2019 05:58AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 112
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready