自定义域
为你的生产部署设置自定义域。
默认情况下,你在 EAS 托管上的生产部署将如下所示: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.
信息 注意:设置自定义域名是高级功能,在免费计划中不可用。有关不同计划和福利的详细信息,请访问 EAS 定价。
先决条件
🌐 Prerequisites
一个带有生产部署的 EAS 托管项目
自定义域名将始终加载生产环境部署。因此,要将自定义域名添加到你的项目中,你首先需要一个已被升为生产环境的部署版本。
🌐 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
- 在你的项目仪表板中,导航到 托管设置。
- 如果你没有生产环境部署,系统会提示你先分配一个。
- 在自定义域下,输入你想要设置的自定义域。支持顶层域名和子域名。如果你拥有
example.com,你可以选择:example.com:顶层域anything.example.com:子域名
- 接下来,系统会提示你在你的 DNS 提供商处填写一些 DNS 记录:
- 验证:用于证明你拥有该域名
- SSL:设置 SSL 证书
- CNAME(子域名)或 A记录(顶层域名):将域名指向你的生产部署
- 按刷新按钮,直到所有检查通过。根据你的 DNS 提供商,这一步通常只需要几分钟。
如果你希望域名更换实现零停机,重要的是按照表格中列出的顺序逐一填写这些记录。 也就是说,首先添加验证 TXT记录,并点击“刷新”,直到界面确认验证记录。然后再添加SSL CNAME记录,直到确认无误,最后设置第三条记录。 如果停机时间不重要或无关紧要,你可以一次性添加全部三条 DNS 记录。
在将自定义域分配给你的应用后,该自定义域将指向你的生产部署。
🌐 After assigning a custom domain to your app, the custom domain will route to your production deployment.
自定义域名 DNS 记录
🌐 Custom domain DNS records
仪表板提供的三条记录中,有两条是用于验证你对域名的所有权。 验证 TXT 记录用于证明你对域名的所有权,因为它添加了一个自定义令牌,可以通过读取回来的方式验证你确实在控制的域名上进行设置。 SSL CNAME 记录用于向证书颁发机构证明你对域名的所有权,也称为域名控制验证(DCV)。这是一个 CNAME 记录,因为续期和验证都委托给自动化流程,这可以防止证书过期。
🌐 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.
- 如果你正在设置
example.com,记录必须分别在_cf-custom-hostname.example.com和_acme-challenge.example.com上创建 - 如果你正在设置
anything.example.com,记录必须分别在_cf-custom-hostname.anything.example.com和_acme-challenge.anything.example.com上创建
最后,仪表板显示的第三个 DNS 条目将始终是指向你的域名到 EAS 托管的实际 DNS 记录。
🌐 Lastly, the third DNS entry that the dashboard presents will always be the actual DNS record that points your domain at EAS Hosting.
- 对于顶层域名,仪表板通常建议使用指向
172.66.0.241的 A 记录 - 对于子域名,仪表板通常建议将 CNAME 记录 指向
origin.expo.app
这两个记录是等效的,但一些 DNS 提供商不允许在顶层域上设置 CNAME 记录。
🌐 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 日 之前已经设置了自定义域名,你必须在按照设置通配符域的说明之前,先在项目的托管设置中按下“刷新”按钮。
虽然每个项目只能设置一个自定义域名,但你可以设置更多的子域名 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上创建一个指向origin.expo.app的 CNAME 记录 - 如果你已经设置了子域名,例如
anything.example.com,请在staging.anything.example.com上创建一个指向origin.expo.app的 CNAME 记录
如果你想将任何子域名请求定向到你创建的任何别名,你可以改为设置通配符 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上创建一个指向origin.expo.app的 CNAME 记录 - 如果你已经设置了子域名,例如
anything.example.com,请在*.anything.example.com上创建一个指向origin.expo.app的 CNAME 记录
通配符 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> 上创建一个指向 origin.expo.app 的 CNAME 记录。
🌐 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.