<p>There's a couple different ways to handle this.</p>
<h1>Base URL on Asset Volume</h1>
<p>One way is just to treat the <a href="https://craftcms.com/docs/3.x/assets.html#volumes" rel="nofollow noreferrer">asset volume</a> like you might a CDN.</p>
<p>Unlike other CMS (ahem WP), Craft doesn't hardcode URLs into the database and will build them up on-the-fly.</p>
<p>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.</p>
<p>Your Asset volume config might look something like:</p>
<p><a href="https://i.sstatic.net/jxIe4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jxIe4.png" alt="enter image description here" /></a></p>
<p>Instead of setting a value in the control panel, you can also use an <a href="https://craftcms.com/docs/3.x/config/#using-aliases-in-control-panel-settings" rel="nofollow noreferrer">alias</a> if you want to advantage of Craft's multi-environment support.</p>
<h1>Server Rewrites</h1>
<p>If you have other assets that aren't necessarily managed by Craft, you can do some server rewrites like you did using Apache's <code>.htaccess</code> config.</p>
<p>Nitro uses nginx as the web server, not Apache, so there's not quite a direct equivalent of <code>.htaccess</code> other than editing the configuration (which is easy enough to do).</p>
<p>You'd want to <a href="https://craftcms.com/docs/nitro/2.x/commands.html#container-ssh" rel="nofollow noreferrer">ssh in</a> to the appropriate container and then edit the nginx config (usually located in <code>/etc/nginx/sites-enabled/yourtestservername</code>.</p>
<p>To make the server rewrite work, try something like:</p>
<pre><code>location ^~ /images {
return https://productionserver.example.com$request_uri;
 }
 
</code></pre>
<p>Place this before the closing bracket &quot;}&quot;. This assumes your asset volume is stored at &quot;/images&quot;. If you have any others, you can add them separately. nginx will redirect any content that's in <code>/images</code> to the production server.</p>

CC BY-SA 4.0
2021-04-27T16:56:34.337Z
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
CC BY-SA 4.0
2022-04-18T18:04:01.180Z
This is very helpful, but what about images that are generated by Craft's transforms? Those seem to require the server path to function.
4midori
CC BY-SA 4.0
2022-04-19T19:36:04.140Z
@4midori: Transforms should work. Did you have a use case? Feel free to ask a new question with more details.
RitterKnight
CC BY-SA 4.0
2021-04-25T18:44:38.510Z
2021-04-25T18:44:38.510Z
RitterKnight
<p>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:</p>
<p>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.</p>
<p>Does anyone know how to achieve this with a Nitro setup?</p>
<p>Thank you so much.</p>

<assets><environments>
Serve remote files instead of local ones (with a nitro setup)
# Serve remote files instead of local ones (with a nitro setup)

(Asked by: username_0 on 2021-04-23)

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.

**Tags:** assets, environments

---

## 1 answers

### Answer by username_1 on 2021-04-25. Score: 1 | Accepted answer

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:

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.

> **Comments:**
> **username_0**: 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!  
> **username_2**: This is very helpful, but what about images that are generated by Craft's transforms? Those seem to require the server path to function.  
> **username_1**: @4midori: Transforms should work. Did you have a use case? Feel free to ask a new question with more details.  

---

