A better "site not available" page

I just loaded this Disourse site and got this:

(I am not asking what happened here - I presume you were rebuilding the docker app or something, it doesn’t matter.)

My query is: How are you achieving a nice error page like this? When I rebuild the app, I just get “502 Bad Gateway / nginx”, something like

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. :smiley:

6 Likes

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.

11 Likes

I’m running such a setup on two instances. Actually, it was quite easy:

My outer nginx is configured as described here, and then I simply added an error_page directive and a location for the error page itself:

        location / {
                error_page 502 =502 /errorpages/discourse_offline.html;
                proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
                proxy_set_header Host $http_host;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
        }

        location /errorpages/ {
                alias /var/www/errorpages/;
        }
}

You might want to set up a nice-looking discourse_offline.html – unluckily, I only have an ugly one :wink:

This will not take care of the 502 Bad Gateway served by Discourse itself while it is starting up, though.

8 Likes

Would you be interested in writing a howto for this? I believe @erlend_sh could even sponsor it!

3 Likes

I might be able to squeeze that in over the weekend, but I cannot promise anything. :slight_smile:

5 Likes

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 :wink:

3 Likes

We now have instructions for this:

6 Likes