【问题标题】:Firebase custom domain 'Needs Setup' with nginx proxy server带有 nginx 代理服务器的 Firebase 自定义域“需要设置”
【发布时间】:2021-07-28 14:33:50
【问题描述】:

我有一个托管在 Firebase 主机上的前端应用。我还有一个在 Digital Ocean 液滴上运行的后端 API。我在 droplet 上安装了 nginx,它将重定向到前端应用程序或后端 API。我的 nginx 配置文件如下所示:

server {
  listen 80;
  return 301 https://$host$request_uri;
}

server {
  listen 443;
  server_name myapp.com *.myapp.com;
  ssl_certificate           /etc/nginx/cert.crt;
  ssl_certificate_key       /etc/nginx/cert.key;
  ssl on;
  ssl_session_cache  builtin:1000  shared:SSL:10m;
  ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
  ssl_prefer_server_ciphers on;

location / {
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    proxy_pass          http://150.101.64.193:80;
    proxy_read_timeout  90;

    proxy_redirect      http://150.101.64.193:80  https://myapp.com;
   }

 location /api/ {
   proxy_pass http://localhost:5000;
   proxy_read_timeout 90;
   proxy_redirect http://localhost:5000 https://localhost:5000;

   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection keep-alive;
   proxy_set_header Host $host;
   proxy_cache_bypass $http_upgrade;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   }

}

Firebase 告诉我将两条 TXT 记录复制到我的 DNS 设置中,但只有在我想将域名映射到前端应用程序时才能让它工作。相反,我的 DNS 设置将我的域名映射到 droplet 的 IP 地址。然后,Droplet 上的代理应根据传递的路由将请求转发到前端或后端。例如

www.myapp.com/blah 重定向到 Firebase 应用 www.myapp.com/api/blah 重定向到 API

目前 Firebase 报告说我的自定义域需要设置,因为没有相应的 TXT 记录。这是我第一次尝试部署 Web 应用程序,所以我不确定此设置是否有效。

【问题讨论】:

    标签: firebase nginx dns webapi


    【解决方案1】:

    如果您使用 NGINX 将流量代理到 Firebase 托管站点,您可能希望将该流量代理到共享域,例如<site>.web.app 而不是重新代理回提供流量的同一个域。

    我们不建议在 Firebase Hosting 前面放置代理,因为这违背了 Firebase Hosting 的全球 CDN 的目的,但它应该可以工作。

    您也可以使用 Cloud FunctionsCloud Run 直接构建您的 API 界面,而不是代理到 NGINX 后端。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 2022-06-15
      • 2020-04-19
      相关资源
      最近更新 更多