Nginx supports X-Accel-Redirect for local files with no extra hassle, but what happens if you need to serve files located in some remote location like s3 and you don’t want to expose direct urls to the files? Sometimes you may want that to have control over stats or to keep an option to migrate to another file server without changing original urls.
Here is what you do:
Then in your application you need to set X-Accel-Redirect header with remote file hostname ( first part ) and URI (second part).
Potentially you could use the same idea for private files stored on S3. For that you would need to generate correct
proxy_set_header Authorization "value";
which might be a little tricky, but possbile with perl support ( extract required tokens from instance metadata if you are using IAM roles, or use access keys passed to the instance somehow ).