Google Cloud LB:更改“服务器错误"默认html页面 [英] Google Cloud LB: Change "server error" default html page
问题描述
默认情况下,如果负载均衡找不到将流量重定向到的后端,例如如果所有可用的后端都关闭,则会显示此 html 页面:
By default, if the load balance can't find a backend to redirect traffic to, for example if all available backends are down, it shows this html page:
成绩单:
服务器遇到临时错误,无法完成您的请求.请在 30 秒后重试.
Error: Server Error
The server encountered a temporary error and could not complete your request. Please try again in 30 seconds.
我想改用我自己的静态 html 页面.
我在 LB + 云存储页面上看到了这个 这里:
I would like to use my own static html page instead.
I saw this on the LB + Cloud storage page here:
您还可以配置自定义索引页面和自定义错误页面,如果请求的对象不存在,则将提供这些页面.这可以通过将网站配置添加到您的 Cloud Storage 存储桶来完成.通过网站配置,您可以直接从您自己域的 Cloud Storage 存储桶中提供静态网页.
You can also configure a custom index page and a custom error page that will be served if the requested object doesn’t exist. This can be done by adding a Website Configuration to your Cloud Storage bucket. With a Website Configuration, you could serve a static webpage directly out of a Cloud Storage bucket from your own domain.
这将如何工作?我知道如何在云存储上托管静态页面,但我将如何将它与 LB 一起使用?
How would that work ? I know how to host static page on cloud storage, but how would I use it with the LB ?
推荐答案
简单地说,你不能,至少现在是这样.
Simply put, you can't, at least for now.
HTTP 负载您发现的带云存储的平衡器处于 alpha 阶段,您需要申请白名单才能试用.但它不会解决你的问题.因为到目前为止,还没有办法根据后端的响应来手动控制负载均衡器的重定向.我认为这永远不可能.这不是 GCP 中负载平衡器的目的.
The HTTP Load Balancer with Cloud Storage you found is in alpha, you will need to request a whitelist to try it. But it won't solve your problem. Because as of now, there is no way to control a load balancer's redirection manully based on the backends' responses. I don't think that will ever be possible. It's not the purpose of a load balancer in GCP.
您还可以配置自定义索引页面和自定义错误页面,如果请求的对象不存在,则会提供这些页面.
You can also configure a custom index page and a custom error page that will be served if the requested object doesn’t exist.
以上语句仅表示您可以为存储桶中未找到的对象提供自定义 404 页面.如果您的后台服务关闭(502),这并不意味着让您重定向流量.两者之间有很大的区别:我找不到页面和没有任何工作,因为我没有服务器.
The above statement only means that you can have a custom 404 page for unfound objects in the bucket. It's not meant to let you redirect traffic if your Back-services are down (502). There is a big difference between : I can't find a page, and Nothing is working because I don't have a server.
您只能将来自外部的流量重定向到网络内部.你不能做相反的事情.您不能要求负载均衡器根据响应进行重定向.
You can only redirect traffic coming from outside toward the inside of your network. You can't do the opposite. You can't ask the load balancer to redirect based on a response.
与其试图让 502 错误页面美观,不如先问问自己为什么会有它,然后尝试解决它.
Instead of trying to make the 502 error page beautiful, ask yourself why you have it in the first place, and try to fix that.
这篇关于Google Cloud LB:更改“服务器错误"默认html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!