Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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