2

现在我已经用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;
  }
4

2 回答 2

0

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

proxy_set_header Host us-central1-app-id.cloudfunctions.net;
于 2019-02-22T20:46:31.617 回答
-2

You probably don't need any NGINX proxy to perform URL routing. You can simply create a firebase hosting project and use the rewrite rules for invoking your cloud functions. I have written in depth about this topic on my blog, have a look.

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

于 2019-09-16T18:53:57.227 回答