自定义域
为你的生产部署设置自定义域。
默认情况下,你在 EAS Hosting 上的生产部署将如下所示:my-app.expo.app
,其中 my-app
是你选择的预览子域名。如果你拥有一个域,你可以将其作为自定义域分配给生产部署。
¥By default, your production deployment on EAS Hosting will look like this: my-app.expo.app
, where my-app
is your chosen preview subdomain name. If you own a domain, you may assign it as a custom domain to the production deployment.
每个项目只能有一个自定义域,该域分配给生产部署。
¥Each project can have exactly one custom domain, which is assigned to the production deployment.
注意:设置自定义域是一项高级功能,在免费计划中不可用。在 电子防盗系统定价 了解有关不同计划和福利的更多信息。
先决条件
¥Prerequisites
An EAS Hosting project with a production deployment
The custom domain will always load the production deployment. Therefore, to add a custom domain to your project, you will need a deployment that's been promoted to production first.
Assigning a custom domain
-
In your project's dashboard, navigate to Hosting settings.
-
If you do not have a production deployment, you'll be prompted to assign one first.
-
Under Custom domain, enter the custom domain you'd like to set up. Both apex domains and subdomains are supported. If you own
example.com
, you can select:example.com
: apex domainanything.example.com
: a subdomain
-
Next, you'll be prompted to fill out some DNS records with your DNS provider:
- Verification: to prove you own the domain
- SSL: to set up SSL certificates
- CNAME (subdomains) or A record (apex domains): to point the domain at your production deployment
-
Press the refresh button until all checks pass. Depending on your DNS provider, this step usually only takes a couple of minutes.
If you require for the domain name switchover to be zero downtime, it's important to fill out these records one by one in the order they are presented in the table. That is, add the Verification TXT record first, and press "Refresh" until the UI confirms the verification record. Then add the SSL CNAME record next until it is confirmed, and set up the third record last. If downtime isn't important or relevant, you may add all three DNS records at once.
After assigning a custom domain to your app, the custom domain will route to your production deployment.
Custom domain DNS records
Two of the three records the dashboard presents you are to validate ownership of your domain. The Verification TXT record proves ownership of your domain, since it adds a custom token that can be read back to verify you're setting the domain up on a domain you control. The SSL CNAME record proves ownership of your domain to a certificate authority, also known as Domain Control Validation (DCV). This is a CNAME record because both renewal and validation is delegated to an automated process, which prevents certificates from expiring.
Both records are created on a subdomain of the custom domain you're setting up.
- If you're setting up
example.com
, the records must be created on_cf-custom-hostname.example.com
and_acme-challenge.example.com
respectively - If you're setting up
anything.example.com
, the records must be created on_cf-custom-hostname.anything.example.com
and_acme-challenge.anything.example.com
respectively
Lastly, the third DNS entry that the dashboard presents will always be the actual DNS record that points your domain at EAS Hosting.
- For apex domains, the dashboard typically recommends an A record to
172.66.0.241
- For subdomains, the dashboard typically recommends a CNAME record to
origin.expo.app
Both of these records are equivalent, however some DNS providers do not allow CNAME records to be set up on apex domains.
Alias and wildcard subdomains
info If you had a custom domain set up already before March 19, 2025, you must press the "Refresh" button in your project's Hosting settings before following instructions for setting up wildcard domains.
While only a single custom domain can be set up per project, you can set up further subdomain DNS records to handle requests for other aliases than just the production alias.Requests will be routed to the deployment whose alias matches the subdomain.
For example, after creating a staging
alias, you may set up CNAME record for your alias:
-
If you've set up an apex domain, for example
example.com
, create a CNAME record onstaging.example.com
set toorigin.expo.app
-
If you've set up subdomain domain, for example
anything.example.com
, create a CNAME record onstaging.anything.example.com
set toorigin.expo.app
If you'd like to direct any subdomain request to any alias you've created, you may instead set up a wildcard CNAME record:
-
If you've set up an apex domain, for example
example.com
, create a CNAME record on*.example.com
set toorigin.expo.app
-
If you've set up a subdomain domain, for example
anything.example.com
, create a CNAME record on*.anything.example.com
set toorigin.expo.app
A wildcard CNAME record always starts with *
and stands for any subdomain.As long as subdomains on your custom domain are set to origin.expo.app
, EAS Hosting will attempt to send the request to the deployment assigned to an alias with a matching name.
The exceptions are www
subdomains.If you've set up a www
subdomain, and no alias named www
exists, the request will be redirected to the custom domain with a 308 response and be treated as a request to the production deployment.If you wish to only set up an automatic redirection for the www
subdomain on your custom domain, create a CNAME record on www.<yourdomain>
set to origin.expo.app
.