# A better "site not available" page

**URL:** https://meta.discourse.org/t/a-better-site-not-available-page/44826
**Category:** Site feedback
**Created:** [26. Mai 2016 um 08:52 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826 "2016-05-26T08:52:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![precessor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/precessor/32/120664_2.png) [@precessor](https://meta.discourse.org/u/precessor)
#### Post date: [26. Mai 2016 um 08:52 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/1 "2016-05-26T08:52:49Z")

</div>

I just loaded this Disourse site and got this:

 ![](https://global.discourse-cdn.com/meta/original/3X/b/c/bcdb003faab2d911794effa9dfc382a1ecf3bf71.png)

(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

 ![](https://global.discourse-cdn.com/meta/original/3X/a/e/ae1cdaab2cf640d408921cca2f0ff0de80b4cdbf.png)

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. 😃

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [26. Mai 2016 um 09:03 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/2 "2016-05-26T09:03:46Z")

</div>

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](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page) and specifying a custom (static) page to load whenever a 502 would otherwise be served.

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [26. Mai 2016 um 11:41 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/3 "2016-05-26T11:41:29Z")

</div>

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

My outer nginx is configured [as described here](https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247), and then I simply added an `error_page` directive and a location for the error page itself:

```plaintext
        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 😉

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [26. Mai 2016 um 19:19 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/4 "2016-05-26T19:19:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [26. Mai 2016 um 19:32 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/5 "2016-05-26T19:32:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![precessor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/precessor/32/120664_2.png) [@precessor](https://meta.discourse.org/u/precessor)
#### Post date: [27. Mai 2016 um 10:51 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/6 "2016-05-27T10:51:38Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [27. Mai 2016 um 19:22 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/7 "2016-05-27T19:22:39Z")

</div>

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 😉

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [4. Juni 2016 um 08:43 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/8 "2016-06-04T08:43:30Z")

</div>

We now have instructions for this:

> [@Add an offline page to display when Discourse is rebuilding or starting up](https://meta.discourse.org/t/adding-an-offline-page-when-rebuilding/45238):
>
> warning This guide is intended for advanced users, who are already using nginx outside the docker container. By following this guide you make your setup more complicated and will lose some speed benefits like HTTP2 if you’re not running Ubuntu 16.04 or later. Proceed with caution! When Discourse is rebuilding or starting up, your users will usually either see an error message from their browser… …or a not-so-nice 502 error message from Nginx: If you’re a perfectionist …

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [4. Juni 2016 um 09:29 UTC](https://meta.discourse.org/t/a-better-site-not-available-page/44826/9 "2016-06-04T09:29:15Z")

</div>


