1 import { Note, InlineIcon, CodeTab, CodeTabs } from "docs-ui"
2 import { EllipsisHorizontal, TriangleRightMini } from "@medusajs/icons"
3
4 export const metadata = {
5 title: `Environment Custom Domains`,
6 }
7
8 # {metadata.title}
9
10 In this guide, you'll learn how to set up custom domains for your backend and storefront deployed on Cloud.
11
12 ## Custom Domains Overview
13
14 By default, Medusa environments are deployed with `medusajs.app` (backend) and `medusajs.site` (storefront) subdomains. You can configure custom domains to use your own branded URLs for both your backend and storefront.
15
16 <Note>
17
18 To update the default `medusajs.app` and `medusajs.site` subdomains instead, see the [Update Subdomains](../subdomains/page.mdx) guide.
19
20 </Note>
21
22 You can configure multiple custom domains per environment, allowing you to use different domains for Production, Staging, and preview environments based on your needs.
23
24 ---
25
26 ## Backend Custom Domains
27
28 Backend custom domains allow you to serve your Medusa backend from your own domain instead of the default `medusajs.app` subdomain.
29
30 <Note>
31
32 Backend custom domains are available for Scale and Enterprise plans only. Learn more about plan features on the [pricing page](../../pricing/page.mdx).
33
34 </Note>
35
36 ### Prerequisites
37
38 To set up a backend custom domain, you need:
39
40 - A domain registered with a domain provider that supports CNAME records
41 - Access to your domain's DNS settings
42
43 ### Set Up Backend Custom Domain
44
45 To set up a backend custom domain:
46
47 1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click **Domains** in the sidebar.
48 2. Under the **Custom backend domains** section, click the **Add domain** button.
49 3. In the modal that opens, enter your custom domain name (for example, `api.acme.com`) and click **Continue**.
50
51 After submitting, you are taken to the DNS configuration detail page where you can add the required DNS records with your domain provider.
52
53 You can track each domain's setup progress with the [Domain Status Indicators](#domain-status-indicators).
54
55 ### Update Backend Domain in Storefront
56
57 To avoid downtime in you storefront while DNS changes propagate for your backend's custom domain, Medusa doesn't update the backend URL set in the storefront automatically. The storefront will still point to the backend's original subdomain.
58
59 Once you've verified that DNS changes have propagated and the custom domain is correctly pointing to the Medusa backend, you need to manually update the backend URL in your storefront's configuration to point to the new custom domain.
60
61 Based on your storefront framework, update the backend environment variable:
62
63 <CodeTabs group="storefront-framework">
64 <CodeTab label="Next.js" value="nextjs">
65
66 ```shell
67 NEXT_PUBLIC_MEDUSA_BACKEND_URL= # Your Medusa backend's URL
68 # Update any other envionment variable that uses the Medusa backend URL
69 # For example:
70 MEDUSA_BACKEND_URL= # Your Medusa backend's URL
71 ```
72
73 </CodeTab>
74 <CodeTab label="SvelteKit / Tanstack Start" value="sveltekit-tanstack">
75
76 ```shell
77 VITE_MEDUSA_BACKEND_URL= # Your Medusa backend's URL
78 # Update any other envionment variable that uses the Medusa backend URL
79 # For example:
80 MEDUSA_BACKEND_URL= # Your Medusa backend's URL
81 ```
82
83 </CodeTab>
84 </CodeTabs>
85
86 To learn how to update environment variables on Cloud, see the [Environment Variables](../environment-variables/page.mdx) guide.
87
88 After updating the backend URL, [redeploy your environment](../../deployments/page.mdx#redeploy-a-deployment). Your live storefront will now connect to your Medusa backend through the new custom domain without any downtime.
89
90 ---
91
92 ## Storefront Custom Domains
93
94 Storefront custom domains allow you to serve your storefront from your own domain instead of the default `medusajs.site` subdomain.
95
96 <Note>
97
98 Storefront custom domains are available for Launch, Scale, and Enterprise plans only. Learn more about plan features on the [pricing page](../../pricing/page.mdx).
99
100 </Note>
101
102 ### Prerequisites
103
104 To set up a storefront custom domain, you need:
105
106 - A domain registered with a domain provider that supports either ALIAS records or top-level CNAME records
107 - Access to your domain's DNS settings
108
109 ### Set Up Storefront Custom Domain
110
111 1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click **Domains** in the sidebar.
112 2. Under the **Custom storefront domains** section, click the **Add domain** button.
113 3. In the modal that opens, enter your custom domain name (for example, `shop.acme.com`) and click **Continue**.
114
115 After submitting, you are taken to the DNS configuration detail page where you can add the required DNS records with your domain provider.
116
117 You can track each domain's setup progress with the [Domain Status Indicators](#domain-status-indicators).
118
119 ---
120
121 ## Multiple Custom Domains for Storefront and Backend
122
123 In some use cases, you may want to apply multiple domains to your project that apply for specific conditions. For example, you may want to have `myshop.uk` for your users in the United Kingdom, and `myshop.dk` for your users in Denmark.
124
125 Medusa supports multiple domains on the [Scale and Enterprise plans](../../pricing/page.mdx), with a three-domain limit per project for Scale plans. If you're on these plans, you can add another domain by following the same flow for [storefront](#storefront-custom-domains) and [backend](#backend-custom-domains).
126
127 After adding these multiple domains, you can choose which one to redirect to in your application's logic. For example, you can add a middleware in your storefront that redirects to the correct domain based on the user's location.
128
129 If you need multiple custom domains for the storefront or backend, make sure to [update your plan to Scale or Enterprise](../../billing/plans/page.mdx#change-plan).
130
131 ---
132
133 ## Domain Status Indicators
134
135 After adding a custom domain, a status badge next to the domain name helps you track the setup progress. The same status is shown in the domain list and on the DNS detail page:
136
137 - **Pending** (gray clock icon): Domain has been added but DNS verification is pending
138 - **Configured** (blue clock icon): DNS records are detected but verification is in progress
139 - **Finalizing** (blue clock icon): All DNS records are verified on your end but the platform has not yet confirmed the domain as active
140 - **Verified** (green checkmark icon): Domain is fully configured and active
141 - **Failed**: DNS verification failed. Use the **Restart Verification** button on the DNS detail page to retry.
142 - **Provisioning failed**: The domain could not be provisioned by the platform. The DNS detail page shows an alert explaining the failure instead of the DNS configuration instructions. Contact support if you see this status.
143
144 Domain activation typically completes within a few minutes to 48 hours, depending on DNS propagation times.
145
146 ---
147
148 ## DNS Configuration Detail Page
149
150 The DNS configuration detail page shows the records you need to add with your domain provider and tracks their verification status. To open it, click the domain name in the **Domains** list.
151
152 The page is organized into check sections:
153
154 - **Ownership**: Verifies that you own the domain.
155 - **SSL**: Verifies that the SSL certificate is correctly configured.
156 - **Proxy**: Verifies that traffic is correctly routed to Cloud. This section only appears for domains that require a proxy check.
157
158 Each section shows whether the corresponding DNS records have been verified. The domain header also shows when the most recent verification check ran.
159
160 ### Provisioning Failure
161
162 If the domain's status is **Provisioning failed**, the DNS detail page replaces the DNS configuration instructions with an alert explaining the failure. The **Check records** and **Restart verification** buttons are not available when provisioning has failed. Contact support if you encounter this state.
163
164 ### Verify DNS Records Manually
165
166 You can trigger an immediate DNS check at any time instead of waiting for the next automatic check by clicking the **Check records** button at the top right of the DNS configuration detail page.
167
168 ### Restart DNS Verification
169
170 To restart the verification process from the beginning at any time, click the **Restart Verification** button at the top right of the DNS configuration detail page.
171
172 ### Remove Custom Domain
173
174 <Note type="warning">
175
176 Removing a custom domain is permanent and may cause downtime if the domain is still in use.
177
178 </Note>
179
180 To remove a custom domain:
181
182 1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click **Domains** in the sidebar.
183 2. Click the <InlineIcon Icon={EllipsisHorizontal} alt="three-dots" /> icon on the domain card you want to remove.
184 3. Select **Remove domain** from the dropdown menu.
185
186 ---
187
188 ## Manage Custom Domains
189
190 ### View All Domains
191
192 In the **Domains** settings of your environment, each custom domain is shown as a card with its domain name and DNS verification status. Click a domain card to open its DNS configuration detail page.
193
194 ### Remove Custom Domain
195
196 <Note type="warning">
197
198 Removing a custom domain will immediately stop serving traffic from that domain. Make sure to update any integrations or client applications before removing a domain.
199
200 </Note>
201
202 To remove a custom domain:
203
204 1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click **Domains** in the sidebar.
205 2. Click the <InlineIcon Icon={EllipsisHorizontal} alt="three-dots" /> icon on the domain card you want to remove.
206 3. Select **Remove domain** from the dropdown menu.
207 4. In the confirmation dialog, type the domain name exactly as shown to confirm the removal.
208 5. Click **Remove Domain** to complete the action.
209
210 ---
211
212 ## Troubleshooting
213
214 ### Re-verify DNS Records
215
216 If you've updated your DNS records and want to trigger an immediate check, open the DNS configuration detail page for your domain and click the **Check records** button. This manually starts a fresh DNS check instead of waiting for the next automatic check. To restart the verification process from the beginning, click **Restart Verification**.
217
218 ### Diagnose DNS Record Issues
219
220 On the DNS records detail page, you can click the <InlineIcon Icon={TriangleRightMini} alt="expand" /> icon for any record whose verification status is failing. This shows:
221
222 - The actual DNS records currently found for that entry, if any.
223 - A `dig` command (macOS/Linux) you can copy and run in your terminal to check the record yourself.
224 - An `nslookup` command (Windows) you can copy and run in your terminal.
225 - A link to [Google's Dig tool](https://toolbox.googleapps.com/apps/dig/) to check the record in your browser.
226
227 The same expandable troubleshooting panel is available during the domain setup flow when you're configuring DNS records for a new domain.
228
229 ### Domain Verification
230
231 If your domain remains in **Pending** or **Configured** status:
232
233 1. **Check DNS records**: Verify that you've added all required DNS records exactly as provided in the DNS setup instructions. Expand any rows marked as failed or unexpected in the DNS records table to see what records were found.
234 2. **Re-verify**: Click the **Check records** button on the DNS configuration detail page to trigger a fresh check, or click **Restart Verification** to restart the verification process from the beginning.
235 3. **Wait for propagation**: DNS changes can take up to 48 hours to propagate globally.
236 4. **Contact support**: If your domain hasn't verified after 48 hours, contact support for assistance.
237
238 ### Storefront Not Connecting to Backend After Custom Domain Setup
239
240 If your storefront isn't connecting to the backend after setting up a backend custom domain, make sure you [updated the backend URL in your storefront's environment variables](#update-backend-domain-in-storefront) and redeployed your environment.