1

I'm new to CraftCMS and slowly learning how to use it. I'm creating a site. The local setup was done with Nitro. I have read about the ways to synchronize data and assets across environments. But I have a special situation:

The client has thousands of images (over 9GB), as we do our development, they are continuously adding new media. We don't want to download all those images, and going through refreshes every time they add new images or edit existing ones. With the previous CMS I used to work with, I could modify a local .htaccess file so that when there is a local image request it would be served from the remote server instead.

Does anyone know how to achieve this with a Nitro setup?

Thank you so much.

1

There's a couple different ways to handle this.

Base URL on Asset Volume

One way is just to treat the asset volume like you might a CDN.

Unlike other CMS (ahem WP), Craft doesn't hardcode URLs into the database and will build them up on-the-fly.

On the local dev server, you just need to set the base url (i.e. server name) of a volume to that of the production server instead of serving locally.

Your Asset volume config might look something like:

enter image description here

Instead of setting a value in the control panel, you can also use an alias if you want to advantage of Craft's multi-environment support.

Server Rewrites

If you have other assets that aren't necessarily managed by Craft, you can do some server rewrites like you did using Apache's .htaccess config.

Nitro uses nginx as the web server, not Apache, so there's not quite a direct equivalent of .htaccess other than editing the configuration (which is easy enough to do).

You'd want to ssh in to the appropriate container and then edit the nginx config (usually located in /etc/nginx/sites-enabled/yourtestservername.

To make the server rewrite work, try something like:

location ^~ /images {
return https://productionserver.example.com$request_uri;
 }
 

Place this before the closing bracket "}". This assumes your asset volume is stored at "/images". If you have any others, you can add them separately. nginx will redirect any content that's in /images to the production server.

1
  • 1
    thank you so much for your generous and clear answer. This all makes sense. It is a joy to hear that, unlike other CMSs out there ;), Craft doesn't store full URLs in the database. I'll bookmark your answer and use it for future reference. Thanks so much!
    – mauricio
    Apr 27 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.