Configuring Nginx as a Pass Through Image Proxy

This post shows how to setup Nginx has a pass-through image proxy server. This is useful for local sandboxes, UAT and QA servers where you copy production database down to but don't want to copy all the user generated images to the non production environment.

The problem

You have a production database with lots of images uploaded by users. For example, has over 11gb of user uploaded images. When you download a data dump of the production DB, it has links to all these images which you don't have. You either have to download and sync all the images locally every time you copy the database, live with broken images or point your static images to the prod server.

Copying images locally is the brute force method and will work. If you have all day to sync up images.

Pointing to the images in prod also works, but if you upload your own images to test functionality... You will not be able to see those new images.


Setup nginx to look for static images locally and if it doesn't find it, go to the production server and pull the image.

This works nicely because you can upload images locally and use those and without downloading one static image you will have access to ALL the production server images. Best of both worlds.

Inside http{} add this:

Those who are using Django, be sure to setup a separate server to serve the static images on your sandbox. Helps unclutter your "runserver" to only real Django calls and also allows you to setup this pass through setup.