Using NGINX’s X-Accel with Remote URLs

Using NGINX’s X-Accel with Remote URLs

We’ve recently been working on a project here at Media Suite using Django served up by NGINX. We have files stored remotely within an S3 bucket and need end users to be able to download them after verifying they have permission. The metadata for the files are stored in the Django database.

[…]

The solution below assumes Django, but it should be easily adaptable to any other server backend.

[…]

In a nutshell this allows the backend to pass off the actual transmission of the file to NGINX, but you still get an initial hook into protecting it or logging the download. It works by the backendDjango in our case – giving the URL in the response headers. NGINX will intercept that and serve the file.

[…]