Created
February 5, 2015 16:10
-
-
Save pudgereyem/c5757e11000cd462b07a to your computer and use it in GitHub Desktop.
Serve Missing Media from a Production Server via Apache/Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Serve Missing Media from a Production Server via Apache/Nginx | |
# When working on the website locally, and you don't want to download (or even have) the images that are used on the live site, a simple redirect solves the problem. You can read a good blog post on this here; <http://rzen.net/serve-missing-media-production-apache-nginx/> by Brian Richards. | |
### | |
### For Apache | |
### | |
# Attempt to load files from production if they're not in our local version | |
# If you have development/production setup, it's neat to use .htaccess to redirect all failed requests to the production server (since we wont want to sync all the uploaded media between the two) | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule (.*) http://yourlivesite.com/wp-content/uploads/$1 | |
</IfModule> | |
### | |
### For Nginx | |
### | |
# Directives to send expires headers and turn off 404 error logging. | |
location ~* .(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires 24h; | |
log_not_found off; | |
try_files $uri $uri/ @production; | |
} | |
location @production { | |
resolver 8.8.8.8; | |
proxy_pass http://example.com/$uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment