User precessor initiated a discussion in the Site feedback category regarding the unappealing “502 Bad Gateway” error displayed when a Discourse site is offline or rebuilding, contrasting it with the polished “site not available” page seen on the Meta site. They inquired how to achieve a similar custom error page. mpalmer explained that Meta serves these pages via HAProxy, but suggested that Nginx users can replicate this using the error_page directive to load a static file instead of the default error. fefrei confirmed the feasibility of this approach, sharing a configuration snippet for an outer Nginx setup that redirects 502 errors to a custom HTML file. While codinghorror encouraged fefrei to write a formal tutorial, potentially with sponsorship, precessor proposed integrating this directly into the Discourse app to handle boot-up errors. fefrei clarified that an outer Nginx is necessary to cover the rebuilding phase and noted that such a setup also handles the brief boot-up window. The discussion concluded with fefrei announcing the publication of a comprehensive guide on adding an offline page when rebuilding.
It would be very nice to have a better “site offline” message. Perhaps this isn’t the purview of Discourse (since if the app is being rebuilt, the webserver is offline, right?), but if any pointers would be appreciated.
We serve the “offline” and “site not found” pages out of haproxy, which runs in front of all our sites (and doesn’t get “rebuilt” in the same way a Discourse instance does). You could teach nginx a similar trick, with the error_page directive and specifying a custom (static) page to load whenever a 502 would otherwise be served.
How about an edit to the standard Discourse app, in which as soon as nginx is starting up, it serves a nicer “hang on a sec…the site may be under maintenance…try again in a moment” message, instead of the unintelligible (to the average user) “Bad Gateway 502” message.
Then after, say, 1 minute, the default 502 error can be served (in case there really is a bad gateway).
Not sure how to go about this though.
This fixes only the few seconds while Discourse is booting. Serving a nicer error page while Discourse is rebuilding already requires an outer nginx, which can also handle the error message while Discourse is booting (as I just found out).
I’m building a howto for this soon-ish – hang tight