自定义域

为你的生产部署设置自定义域。


默认情况下,你在 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.

A domain name

You will need to own a domain name you want to use.

Assigning a custom domain

  1. In your project's dashboard, navigate to Hosting settings.

  2. If you do not have a production deployment, you'll be prompted to assign one first.

  3. 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 domain
    • anything.example.com: a subdomain
  4. 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
  5. 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

如果你在 2025 年 3 月 19 日之前已设置自定义域名,则必须先按下项目 托管设置 中的 "刷新" 按钮,然后才能按照设置通配符域名的说明进行操作。

¥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.

虽然每个项目只能设置一个自定义域,但你可以设置更多子域 DNS 记录来处理除生产别名之外的其他别名的请求。请求将被路由到别名与子域名匹配的部署。

¥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.

例如,在 创建 staging 别名 之后,你可以为别名设置 CNAME 记录:

¥For example, after creating a staging alias, you may set up CNAME record for your alias:

  • 如果你设置了顶层域名,例如 example.com,请在 staging.example.com 上创建一条 CNAME 记录,并将其设置为 origin.expo.app

    ¥If you've set up an apex domain, for example example.com, create a CNAME record on staging.example.com set to origin.expo.app

  • 如果你设置了子域名,例如 anything.example.com,请在 staging.anything.example.com 上创建一条 CNAME 记录,并将其设置为 origin.expo.app

    ¥If you've set up subdomain domain, for example anything.example.com, create a CNAME record on staging.anything.example.com set to origin.expo.app

如果你想将任何子域名请求定向到你创建的任何别名,你可以改为设置通配符 CNAME 记录:

¥If you'd like to direct any subdomain request to any alias you've created, you may instead set up a wildcard CNAME record:

  • 如果你设置了顶层域名,例如 example.com,请在 *.example.com 上创建一条 CNAME 记录,并将其设置为 origin.expo.app

    ¥If you've set up an apex domain, for example example.com, create a CNAME record on *.example.com set to origin.expo.app

  • 如果你设置了子域名,例如 anything.example.com,请在 *.anything.example.com 上创建一条 CNAME 记录,并将其设置为 origin.expo.app

    ¥If you've set up a subdomain domain, for example anything.example.com, create a CNAME record on *.anything.example.com set to origin.expo.app

通配符 CNAME 记录始终以 * 开头,代表任何子域名。只要你的自定义域名上的子域名设置为 origin.expo.app,EAS Hosting 就会尝试将请求发送到分配了匹配名称的别名的部署。

¥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.

www 子域名除外。如果你设置了 www 子域名,但不存在名为 www 的别名,则请求将被重定向到自定义域名并返回 308 响应,并被视为对生产部署的请求。如果你只想为自定义域名上的 www 子域名设置自动重定向,请在 www.<yourdomain> 上创建一条 CNAME 记录,并将其设置为 origin.expo.app

¥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.