使用LOAD BALANCER和CDN在Google Cloud Storage上部署水疗应用程序

发布于 2025-02-08 06:23:24 字数 528 浏览 2 评论 0 原文

我正在研究一种使用GCS,Load Balancer和CDN在Google Cloud上部署Angular或React Web应用程序的方法。

我已经使用 urlrewrite 设置了LB和GC,但是由于LB不允许完整的URL重写 pathprefixrefixrewrite ,所以我不能将所有请求重定向到 /index.html

我想实现与firebase托管相同的功能,您可以在其中指定重写规则

"rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]

另一个选项是将404页面设置为 index.html < /code>,但这将导致 404状态代码由服务器返回,我不喜欢。

负载平衡器是否可以使用,因为它们不支持完整的重写?

I'm investigating a way of deploying an Angular or React web application on Google Cloud using GCS, Load Balancer, and CDN.

I've set up the LB and the GCS using the urlRewrite, but since the LB does not allow full URL rewrite only pathPrefixRewrite, I cannot redirect all the requests to /index.html

I want to achieve the same functionality as firebase hosting where you can specify the rewrite rules

"rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]

Another option will be to set the 404 page as index.html, but that will result in a 404 status code return by the server, which I don't like.

Is this possible with Load Balancer, because they are not supporting a full rewrite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缘字诀 2025-02-15 06:23:24

Google在2020年添加了重写引擎(请参阅 https:> https:> https: //serverfault.com/questions/927143/how-to-manage-manage-url-rewrites-with-a-gcp-load-balancer/1045214 ),它仅具有功能的 pathprefixrewrite (剥离固定前缀)。

对于SPA,您需要变量后缀重写为 index.html ,因此您使用nginx或firebase。

或在Buck的HTTP服务器中提到的错误处理程序(您的虚拟URL http Code 404的下跌):

gsutil web set -m index.html -e index.html gs://web-stage/

设置SPA应用程序的完整说明在这里: Google Cloud Load Balancer为Firebase Hosting创建后端服务,以服务微服务&amp; amp;通过负载平衡器来自同一域的前端水疗中心?

讨论LB重写发动机限制:

Google added rewrite engine in 2020 (see https://serverfault.com/questions/927143/how-to-manage-url-rewrites-with-a-gcp-load-balancer/1045214) and it is only capable pathPrefixRewrite (stripping fixed prefix).

For SPA you need variable suffix rewrite to index.html so you use Nginx or Firebase.

Or mentioned error handler in bucket's HTTP server (with a downside of HTTP code 404 for your virtual URLs):

gsutil web set -m index.html -e index.html gs://web-stage/

Full instructions to set SPA app is here: Google cloud load balancer create backend service for Firebase Hosting to serve microservices & frontend SPA from the same domain via load balancer?

Discussion of LB rewrite engine limitations:

芯好空 2025-02-15 06:23:24

现在,使用全局外部负载平衡器路由规则可以重写每个云存储请求以服务index.html。

defaultService: projects/xxxx/global/backendBuckets/dashboard
name: path-matcher-1
routeRules:
- matchRules:
  - pathTemplateMatch: /**
  priority: 10
  service: projects/xxxx/global/backendBuckets/dashboard
  routeAction:
    urlRewrite:
      pathTemplateRewrite: /index.html

It's now possible with the global external load balancer routing rules to rewrite every cloud storage request to serve the index.html.

defaultService: projects/xxxx/global/backendBuckets/dashboard
name: path-matcher-1
routeRules:
- matchRules:
  - pathTemplateMatch: /**
  priority: 10
  service: projects/xxxx/global/backendBuckets/dashboard
  routeAction:
    urlRewrite:
      pathTemplateRewrite: /index.html
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文