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.

🎉


Read Next



2024 Goals
Write Things