Skip to content

Instantly share code, notes, and snippets.

@iansvo
Created August 7, 2023 16:40
Show Gist options
  • Save iansvo/5977caf12d1df19e96ca67f550cb3afa to your computer and use it in GitHub Desktop.
Save iansvo/5977caf12d1df19e96ca67f550cb3afa to your computer and use it in GitHub Desktop.
Open the Nginx configuration for your site and look for a server block that listens for port 443. Look for something like Listen 127.0.0.1:443 ssl in the server { ... } block to find the right one. Add the following location rules near the top of the block, after any other definitions.
set $production your-prod-server.com;
# Redirect requests to /wp-content/uploads/* to production server
location @prod_uploads {
rewrite "^(.*)/wp-content/uploads/(.*)$" "https://$production/wp-content/uploads/$2" break;
}
# Rule for handling local requests for images
location ~ "^/wp-content/uploads/(.*)$" {
try_files $uri @prod_uploads;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment