-
-
Save lwl5219/8993e79f85d897c4d557bfbaafacca19 to your computer and use it in GitHub Desktop.
nginx remote file proxying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location ~* ^/remote-files/(http[s]*://)(.*?)/(.*) { | |
# Do not allow people to mess with this location directly | |
# Only internal redirects are allowed | |
internal; | |
# nginx has to be able to resolve the remote URLs | |
resolver 8.8.8.8; | |
# Location-specific logging | |
#access_log /usr/local/etc/nginx/logs/internal_redirect.access.log main; | |
error_log /usr/local/etc/nginx/logs/internal_redirect.error.log warn; | |
# Extract download url from the request | |
set $download_uri $3; | |
set $download_host $2; | |
set $download_protocol $1; | |
# Compose download url | |
set $download_url $download_protocol$download_host/$download_uri; | |
# The next two lines could be used if your storage | |
# backend does not support Content-Disposition | |
# headers used to specify file name browsers use | |
# when save content to the disk | |
proxy_hide_header Content-Disposition; | |
add_header Content-Disposition 'attachment; filename="$args"'; | |
# Do not touch local disks when proxying | |
# content to clients | |
proxy_max_temp_file_size 0; | |
# Download the file and send it to client | |
proxy_pass $download_url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on http://kovyrin.net/2010/07/24/nginx-fu-x-accel-redirect-remote/