Skip to content

Instantly share code, notes, and snippets.

@casivaagustin-zz
Created February 27, 2014 23:04
Show Gist options
  • Save casivaagustin-zz/9261586 to your computer and use it in GitHub Desktop.
Save casivaagustin-zz/9261586 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