如何检测应用程序启动失败?
我们的情况:
我们在 loabalancer(Astaro 安全网关)后面有多个网络服务器。在网络服务器上,我们运行一个 ASP.NET 应用程序,并为 404 和 500 状态代码配置了自定义错误页面。
现在,当应用程序无法启动时,每个请求都会通过发送状态代码 302 重定向到错误页面,然后错误页面本身会发送 500。
负载均衡器每 15 秒向我们的网络服务器发送一个 HEAD 请求,以查看其是否仍然存在,如果是,则返回检查第一个 html 状态代码。所以它只看到 302。低于 500 的每个代码都被视为服务器已启动并正在运行。
问题:
如果应用程序无法启动,我们如何才能使负载平衡发挥作用?
编辑:
按应用程序无法启动我的意思是在启动过程中出现错误。一些重要部分无法初始化,因此每个页面都无法执行。
Our Situation:
We have several webservers behind a loabalancer (Astaro Security Gateway). On the webservers we run an asp.net application and we have customerrorpages configured for 404 and 500 status codes.
Now when the Application fails to start every request is redirected to the errorpage by sending status code 302 and the errorpage itself then sends a 500.
The loadbalancer sends a HEAD request to our webservers every 15 seconds to see if its still alive and if so it checks the first html status code. So it only sees the 302. Every code below 500 is treated as server is up and running.
Question:
How can we make our loadbalancing work if the application failed to start?
Edit:
By Application failed to start I mean that during the startup there were errors. Some essential parts could not be initialilzed and therefore every page fails to execute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法:
在您的 web.config 中的 customErrors 模式中设置
redirectMode
到ResponseRewrite
- 这会删除从服务器到错误页面的 302 重定向 - 这也有一个令人高兴的巧合,即使用 can轻松查看他们请求的原始页面是什么,如果可能解决问题,可以使用 F5 重试。如果您要挂钩 ApplicationError 事件,请确保使用
Server.Transfer
代替重定向到错误页面。我的 web.configs 之一中有以下内容:
然后在我的 ErrorHandler 页面中,我检查服务器的最后一个错误,并配置这些错误:
显然,您可能想要进行额外的处理 - 例如,在我执行所有这些操作之前,我将原始请求与我的重定向数据库进行比较,以检查移动的内容/虚荣网址,并且只有在找不到合适的重定向时才会回退到此。
A couple of ways:
In your web.config on the customErrors mode set the
redirectMode
toResponseRewrite
- this removes the 302 redirect from the server to the error page - this also has the happy coincidence that uses can easily see what the original page they requested was, and can retry with an F5 if that's likely to resolve the issue.If you are hooking into the ApplicationError event, make sure that rather than redirecting to your error pages you use
Server.Transfer
instead.I have the following in one of my web.configs:
Then in my ErrorHandler page I check for the last error from the server, and configure those:
Obviously you may want to do additional processing - for example before I do all this I'm comparing the original request with my Redirects database to check for moved content/vanity urls, and only falling back to this if I couldn't find a suitable redirect.