You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Firebase Hosting模拟器配置https://localhost:5000访问?

配置Firebase Hosting模拟器支持HTTPS本地访问(localhost:5000)

当然可以通过配置本地开发证书来实现,以下是具体步骤:

1. 生成受信任的本地开发证书

推荐用mkcert工具生成系统信任的SSL证书,比OpenSSL操作更简便:

  • 安装mkcert:
    • macOS:brew install mkcert
    • Windows:choco install mkcert
    • Linux:sudo apt install mkcert
  • 初始化本地根CA(让系统信任后续生成的证书):
    mkcert -install
    
  • 生成localhost对应的证书文件:
    mkcert localhost
    
    执行后会得到localhost.pem(公证书)和localhost-key.pem(私钥)两个文件,将它们放到你的Firebase项目根目录。

2. 修改Firebase配置文件

打开项目根目录的firebase.json,在hosting的emulators节点下添加SSL配置:

{
  "hosting": {
    "public": "public",
    // 保留你原有的Hosting配置
    "emulators": {
      "host": "localhost",
      "port": 5000,
      "ssl": {
        "cert": "./localhost.pem",
        "key": "./localhost-key.pem"
      }
    }
  }
}

3. 启动Firebase Hosting模拟器

运行以下命令启动模拟器:

firebase emulators:start --only hosting

启动成功后,模拟器就会通过HTTPS协议监听https://localhost:5000。

4. 验证访问

打开浏览器访问https://localhost:5000,确认没有证书警告。如果仍有警告,检查:

  • mkcert -install是否成功执行(部分系统需要管理员权限)
  • firebase.json中证书文件的路径是否配置正确

内容的提问来源于stack exchange,提问作者Dživo Jelić

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 02:05:59