使用LOAD BALANCER和CDN在Google Cloud Storage上部署水疗应用程序
我正在研究一种使用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状态代码
由服务器返回,我不喜欢。
负载平衡器是否可以使用,因为它们不支持完整的重写?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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的下跌):
设置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):
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:
现在,使用全局外部负载平衡器路由规则可以重写每个云存储请求以服务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.