Firebase Hosting 上线检查清单(10 项)

2026 年 Firebase Hosting 上线前的 10 项检查清单——涵盖域名、SSL、缓存、跳转、sitemap、Search Console、回滚演练。

你正准备把真实域名指到 Firebase Hosting。dev 没问题、*.web.app 没问题。切 DNS 之前过一遍这 10 项——每一项都是哪个独立开发者被坑过至少一次的事。

问题背景

大多数”上线第一天爆炸”都是可以提前避免的。修复方法都是 5 分钟的事,问题是你想不起来:trailing slash 规则、sitemap 没交、cache header 漏配。这份清单帮你不用上线那天满地灭火。

实操步骤

  1. firebase.jsonpublic 要对得上真实 build 目录。 Astro 是 dist、Next 静态导出是 out、Vite 是 dist。一份生产可用的静态内容站完整配置:
{
  "hosting": {
    "site": "your-firebase-project",
    "public": "dist",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "cleanUrls": true,
    "trailingSlash": true,
    "redirects": [
      { "source": "/blog/:slug", "destination": "/articles/:slug", "type": 301 }
    ],
    "headers": [
      {
        "source": "/_astro/**",
        "headers": [
          { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
        ]
      },
      {
        "source": "**/*.html",
        "headers": [
          { "key": "Cache-Control", "value": "public, max-age=300, s-maxage=3600" }
        ]
      },
      {
        "source": "**",
        "headers": [
          { "key": "X-Content-Type-Options", "value": "nosniff" },
          { "key": "Referrer-Policy",        "value": "strict-origin-when-cross-origin" }
        ]
      }
    ]
  }
}
  1. 确定主域:apex 还是 www。 Firebase Console → Hosting → Add custom domain 把两个域都加上,非主域设 redirect。apex 做主时典型 DNS 记录:
Type   Name        Value
A      @           199.36.158.100
A      @           199.36.158.101
CNAME  www         your-project.web.app
  1. 流量切过去前,两个主机名 SSL 都要 OK:
curl -vI https://yourdomain.com 2>&1 | grep -E 'subject:|issuer:|HTTP'
# subject: CN=yourdomain.com
# issuer: C=US, O=Google Trust Services LLC, CN=...
# HTTP/2 200

看到 subject: CN=*.web.app 说明自定义域证书还没签发——等,不要切 DNS。

  1. trailing slash / cleanUrls 规则——无痕窗口几种路径都测一遍:
curl -sI https://yourdomain.com/about    | head -1   # 期望 301 或 200
curl -sI https://yourdomain.com/about/   | head -1   # 期望 200
curl -sI https://yourdomain.com/missing/ | head -1   # 期望 404,不能是 200
  1. 线上 URL 跑 Lighthouse。 Performance 和 Best Practices 目标 > 90:
npx lighthouse https://yourdomain.com/ \
  --only-categories=performance,best-practices,seo \
  --chrome-flags="--headless" --quiet
  1. sitemap 只提交到主域。 *.web.app 不提,apex + www 也不要都提:
Search Console → Sitemaps → 添加新 sitemap
URL: https://yourdomain.com/sitemap-index.xml
  1. canonical 和 og:url 全指向生产主域。 build 产物里扫一遍:
grep -ROIE 'rel="canonical"|og:url' dist | grep -v yourdomain.com | head
# 任何输出 = HTML 里漏了非主域
  1. 回滚提前演练。 Firebase 保留最近约 10 个 release:
firebase hosting:releases:list
# release-1 (当前)   2026-05-22 14:02  abc123
# release-0          2026-05-22 13:40  def456

# 故意推一个已知有问题的版本,再回滚
firebase deploy --only hosting    # 生成新 release
# 控制台:Hosting → Release history → ... → Rollback
  1. 设预算告警。 GCP Console → Billing → Budgets & alerts,50% 和 90% 各一次。纯静态站基本不会触发。

  2. 切 DNS 前最后检查,直接对 *.web.app URL 执行:

curl -s https://your-project.web.app/sitemap-index.xml | grep -c '<loc>'
curl -s https://your-project.web.app/robots.txt | head
curl -sI https://your-project.web.app/         | grep -i cache-control

三项都对,就可以切 DNS 了。

容易踩的坑

  • 没定主域,结果 apex 和 www 都被 Google 收录。
  • sitemap 交到了非主域——浪费抓取预算。
  • 换新域名后忘了改 social meta(og:url)。
  • 没演练回滚就周五上线。
  • sitemap 或 canonical 里还留着 *.web.app

这篇适合谁

所有 2026 年用 Firebase Hosting 做真正上线的独立开发者。

这篇不适合谁

还在 preview channel、还没绑真实域名的,只用前 5 项。

FAQ

  • 切 DNS 后多久流量稳定?: 提前把 TTL 调小的话,5-30 分钟内大部分世界就指到新 host 了。完全传播最长 24 小时。
  • 上线后能关掉 *.web.app 域名吗? — 关不掉,但可以通过 canonical 和 og:url 都指向自定义域名,搜索 / 社交就不会收 *.web.app
  • 需要 robots.txt 吗?: 需要。哪怕只是写一行 sitemap 链接,也能让爬虫快速找到 sitemap。
  • 刚上线发现重大 bug 怎么办?: Hosting > Release history > 回滚到上一个版本,然后修完再部。停机一般一分钟以内。

相关阅读

标签: #独立开发 #Firebase #部署 / 托管 #工作流 #SEO