File Downloads with reverse proxy
Callum Scott
scott.callum at gmail.com
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 '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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190315/29490db9/attachment.html>
More information about the nginx
mailing list