location ~* /internal_data_s3/(.*?)://(.*?)/(.*) {
internal;
set $xfEtag $upstream_http_etag;
set $download_protocol $1;
set $download_host $2;
set $download_path $3;
set $download_url $download_protocol://$download_host/$download_path;
resolver 127.0.0.1 ipv6=off;
proxy_set_header Host $download_host;
proxy_set_header Authorization '';
proxy_set_header Cookie '';
proxy_max_temp_file_size 0;
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirect;
proxy_pass $download_url$is_args$args;
proxy_hide_header Content-Disposition;
proxy_hide_header Content-Type;
proxy_hide_header Etag;
proxy_hide_header x-amz-request-id;
add_header Etag $xfEtag;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
}
location @handle_redirect {
resolver 127.0.0.1 ipv6=off;
set $saved_redirect_location '$upstream_http_location';
proxy_pass $saved_redirect_location;
}