Skip to content

Instantly share code, notes, and snippets.

@emdecr
Last active July 28, 2020 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emdecr/e807e5028670dc2a51faeba65305a44f to your computer and use it in GitHub Desktop.
Save emdecr/e807e5028670dc2a51faeba65305a44f to your computer and use it in GitHub Desktop.
Serve missing media from a production server when dev site is at a subdirectory.
# Case: Dev site hosted at subdirectory (NGINX)
# ie. https://dev.site/sub
# Serve Missing Media from a Production Server
# https://rzen.net/serve-missing-media-production-apache-nginx/
location ~* \.(js|css|png|jpe?g|gif|ico)$ {
expires 24h;
log_not_found off;
try_files $uri $uri/ @production;
}
# Remove subdirectory from redirect
# https://stackoverflow.com/questions/33218367/nginx-proxy-pass-remove-path-prefix-resolve-dns
location @production {
resolver 8.8.8.8;
rewrite ^/sub/(.*) /$1 break;
proxy_pass https://production.site/$uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment