I work on a Macbook Pro and manage a whole bunch of trellis/sage sites. Today I noticed that my available disk space is disappearing VERY quickly, because every time I set up a local dev, I have to rsync down all of the images from the staging/production sites in order for them to look/function right for development. For a lot of the devs I set up, I won’t even touch them for months afterwards until a new request comes through. I don’t want all these images hogging up all my disk space when I only need them every few months or a few times a year…
I did some searching and found some promising things. Some people said I could edit the /etc/nginx/nginx.conf file to have all missing images redirect from staging/production:
html {
server {
location ~* ^.+\.(svg|svgz|jpg|jpeg|gif|png|ico|bmp)$ {
try_files $uri @image_fallback;
}
location @image_fallback {
proxy_pass http://{PROD};
}
}
}
I haven’t been able to get this to work though. I add this, restart nginx with no errors, and there is no change and all images are still missing.
Someone else said to try a Chrome plugin to achieve this, but I couldn’t get that to work either.
Am I doing something wrong? Is there a different solution that is built to work with the Trellis framework? I don’t know much about nginx, I’m basically just copying and pasting and hoping something will stick…
Hmmm… I’ve never thought about that possibility! That might be a good thing to do going forward for new sites we develop, but I’d still like to know how to redirect for all of the existing sites we’ve already built. We don’t exactly have the free time go through all these old sites and offload all of the images… Not immediately, anyway.
Funny, as I was just searching in my archive for a .htaccessI wrote some time ago to load content from the /uploads folder from the production server. However this is mainly for Apache and the file goes to /app/uploads/.htaccess. Maybe this is more interesting for Bedrock users…
I needed a solution for this again as I came to another situation in which the production media library has around 40GB. And I really do not want to download that.
My solution is:
1.) Site specific configs are saved in /etc/nginx/sites-enabled
2.) Edit the specific file such as example.test.conf
3.) Add the following within server and before other locationrules. Don’t forget to set the live URL where to get the resources.
This is not update proved. So I guess reprovision the local server will destroy the setting. Maybe @ben has a proper solution where to add this to let ansible add the rules.
Rather than relying on Trellis, you can simply use PHP to filter the attachment URLs and replace the local domain with production domain, resulting in media files pointing to production files.
A simple MU plugin can be written to check the current environment and do the replacements as required.