How to proxy files from firewalled server through rails application
I have a rails application running on Nginx which needs to serve files for download from another internal server. The internal server uses a dynamic url to generate the file for download, so it isn't a static file sitting in a folder. Both the rails server and server with the files are on the same LAN but only the rails server is open to the public on port 80.
Additionally the files that I'm wanting to serve are anywhere from 5GB - 200GB so I don't want to tie up the rails process for the whole download if that is possible. Is there a way to do this with Net::HTTP + send_data? Or perhaps some kind of Nginx proxy rule?
From inside the LAN you can download a file with a url like this:
http://username:password@192.168.0.5/export?uuid=1234567890
The problem 开发者_StackOverflowis 1) there is no access control for that url, with the user / pass you can download any file you want by passing in it's uuid parameter and 2) the server is only LAN accessible.
I figured out the answer to this question by following the tutorial here: http://kovyrin.net/2010/07/24/nginx-fu-x-accel-redirect-remote/
To handle the HTTP Basic authentication you need to add this line to your nginx config:
proxy_set_header Authorization "Basic BASE64_USER_PASS";
Where BASE64_USER_PASS is a base64 string of your username and password in the format "user:pass"
精彩评论