首页 > 解决方案 > Firebase 将多个子域托管到具有 1 个项目的应用目录

问题描述

我目前有一个部署到 Firebase 托管的应用程序,其结构如下:

public/
    appSub1/
        index.html
    appSub2
        index.html
    index.html

我已经添加并连接了我的子域,这样

appSub1.mysite.com/ -> app.firebaseapp.com/
appSub2.mysite.com/ -> app.firebaseapp.com/

我正在尝试配置重定向以将子域与正确的应用程序子文件夹正确关联,以便

appSub1.mysite.com/ -> app.firebaseapp.com/appSub1/
appSub2.mysite.com/ -> app.firebaseapp.com/appSub2/

如果我手动添加子路径,应用程序仍然可以正确显示,但没有它们。所以会以appSub1.mysite.com/空白页结束,但会以appSub1.mysite.com/appSub1/正确的方式结束index.html

这是我当前的托管配置firebase.json

"hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "appSub1.mysite.com/**",
        "destination": "/appSub1/**",
        "type": 301
      },
      {
        "source": "appSub2.mysite.com/**",
        "destination": "/appSub2/**",
        "type": 301
      }
    ]
  },

标签: firebasednssubdomainfirebase-hosting

解决方案


我推荐以下内容:

  1. 在 Firebase 上升级到 Blaze 计划
  2. 使用 Firebase 多站点托管方法(参考:https ://firebase.google.com/docs/hosting/multisites )
  3. 分成两个单独的托管项目目标 - 比如说public/app1和- 因此,默认情况下托管地址将是和(或者现在截至 2019 年 5 月,您还将获得一个域 -public/app2app1app2app1.firebaseapp.comapp2.firebaseapp.com.web.appapp1.web.app
  4. 通过在域注册表上配置 DNS 条目来连接各个子域(请参阅:https ://medium.com/@fransandi/use-firebase-multisite-hosting-to-associate-multiple-domains-subdomains-to-your-project-ee099109bfe9 )

推荐阅读