Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mauriciogofas/5145d37a344b8b9a76b9fa1803e18c1a to your computer and use it in GitHub Desktop.
Save mauriciogofas/5145d37a344b8b9a76b9fa1803e18c1a to your computer and use it in GitHub Desktop.
nginx location rule to redirect non existing images to another server
#Rewrites the request, extracting a fragment of the file name and using a remote server.
location @fetchFromRemote {
rewrite ^/path/to/images/(.*)$ http://remoteserver.com/other/path/to/images/$1 redirect;
}
#Will try to see if we have the file in this server, is not will use fetchFromRemote
location ~ ^/path/to/images/.*(png|jpg|jpeg|gif|ico|swf)$ {
try_files $uri @fetchFromRemote;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment