Fix Missing Assets When Developing Craft CMS Locally

Often when I'm working with Craft CMS I'll download a database dump from production and use it locally so I can test with real data.

The only problem with this is that the production database will usually contain a lot of references to images which have been uploaded to Craft's assets folders.

Rather than download all of these I've added this super useful bit of functionality to my local nginx config:

location /assets-base {
    try_files $uri $uri/ @router;
    error_page 403 = @router;
    error_page 404 = @router;
}

location @router {
    rewrite ^(.*)$ https://productionsite.com/$1;
}

Essentially, if nginx can't find a local file in the assets upload folder which has been requested, grab it from the live site instead.

It works a treat and allows me to download a DB dump from prod whenever I like without having to keep image files in sync.

🎉


Next Up



2018 Goals
Earn £100 'passive' income
(£0/£100)
Increase net worth from £X to £X
Invoice £70k active income
(£92k/£70k)
Launch a passive income potential product
(0/1)
Present 5 talks
(3/5)
Write One Blog Post Per Week
(14/25)