【问题标题】:Custom url with firebase cloud function with nginx reverse proxy?带有firebase云功能的自定义url和nginx反向代理?
【发布时间】:2017-12-06 12:50:30
【问题描述】:

现在我已经用 firebase 开发了云功能,部署后我得到了类似这样的端点

https://us-central1-app-id.cloudfunctions.net/api/path/of/api/

我的问题是,是否可以使用 nginx 代理将自定义域映射到此端点

http://my-domain.com/path/of/api/

经过一些实验,我在将自定义域链接到云功能后得到了这个错误

404. That’s an error.

The requested URL /path/of/api/ was not found on this server. That’s all we know.

这是我在 nginx 上的配置

  location /path/of/api/ {
    proxy_http_version 1.1;
    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_set_header Connection "Keep-Alive";
    proxy_set_header Proxy-Connection "Keep-Alive";
    proxy_cache_bypass $http_upgrade;
    proxy_pass https://us-central1-app-id.cloudfunctions.net/api;
  }

【问题讨论】:

    标签: firebase nginx google-cloud-functions nginx-reverse-proxy


    【解决方案1】:

    您需要将Host 设置为us-central1-app-id.cloudfunctions.net,例如在您的配置中:

    proxy_set_header Host us-central1-app-id.cloudfunctions.net;
    

    【讨论】:

      【解决方案2】:

      您可能不需要任何 NGINX 代理来执行 URL 路由。您可以简单地创建一个 firebase 托管项目并使用重写规则来调用您的云功能。我已经在我的博客上深入地写过这个话题,看看吧。

      https://blog.emad.in/firebase-cloud-functions-with-nginx-like-reverse-proxy/

      【讨论】:

        猜你喜欢
        • 2018-02-09
        • 2021-06-22
        • 2021-09-10
        • 2016-03-31
        • 2020-09-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-04
        相关资源
        最近更新 更多