I am serving my FastCGI application in Apache2 using the standalone FastCGI server and the FastCgiExternalServer directive.
When I restart my FastCGI app my users get a 500 error. What can I do to prevent this? I want to show them a nice 'maintenance' page or something.
It is a Catalyst application written 开发者_StackOverflow社区in perl and I have followed the example here but I have found that a 500 is served and not a 502 bad gateway so I can't select what error to show. I don't want to serve a maintenance page for a legitimate internal server error.
Your only real choices are
- Use
ErrorDocument 500
and design a page that's suitable for either situation, or - Hack/fix mod_fastcgi to return a 502 instead of a 500 like the folk wisdom thinks it should.
mod_fastcgi development is very slow, but not completely dead, so you could always try sending that patch upstream; if it was accepted it would be appreciated. :)
Thanks Hobbs,
I took your advise and created a patch file. This is working for me. I know this is an old question, but it helped me, hopefully this will help others.
--- mod_fastcgi-SNAP-0910052141/mod_fastcgi.c 2008-11-09 07:31:03.000000000 -0700
+++ mod_fastcgi-SNAP-BadGateway/mod_fastcgi.c 2012-06-01 10:42:48.497212761 -0600
@@ -1670,7 +1670,7 @@
if (open_connection_to_fs(fr) != FCGI_OK)
{
ap_kill_timeout(r);
- return HTTP_INTERNAL_SERVER_ERROR;
+ return HTTP_BAD_GATEWAY;
}
is_connected = 1;
@@ -2079,7 +2079,7 @@
if (open_connection_to_fs(fr) != FCGI_OK)
{
ap_kill_timeout(r);
- return HTTP_INTERNAL_SERVER_ERROR;
+ return HTTP_BAD_GATEWAY;
}
set_nonblocking(fr, TRUE);
@@ -2387,6 +2387,11 @@
{
sink_client_data(fr);
}
+
+ //if we failed to connect to FastCGI Server, return error now. Do not try to parse headers
+ if (rv == HTTP_BAD_GATEWAY) {
+ return rv;
+ }
while (rv == 0 && (BufferLength(fr->serverInputBuffer) || BufferLength(fr->clientOutputBuffer)))
{
精彩评论