# 为 Discourse 重建或启动时添加一个离线页面显示

**URL:** <https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238>\
**Category:** Sysadmins\
**Tags:** configuring, how-to, advanced-setup\
**Created:** [2016年六月4日 08:41 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238 "2016-06-04T08:41:48Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)\
**Post date:** [2017年十一月13日 17:14 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/61 "2017-11-13T17:14:15Z")

</div>

That’s exactly the way I got it to work, this is why I had that one question so I asked. that setup is really a life saver in terms of crowd retention.

Thanks

---

<div class="post-metadata">

**Author:** ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)\
**Post date:** [2017年十一月13日 18:28 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/62 "2017-11-13T18:28:15Z")

</div>

Also, this tutorial comes in handy if one doesn’t want to use the webroot module!

Slight configuration change is required to the default vhost then this will work just fine!

> **[How To Secure Nginx with Let's Encrypt on Ubuntu 16.04 | DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)**
>
> In this tutorial, we will show you how to use Let’s Encrypt to obtain a free SSL certificate and use it with Nginx on Ubuntu 16.04. We will also show you how…

---

<div class="post-metadata">

**Author:** ![barreeeiroo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barreeeiroo/32/165264_2.png) [@barreeeiroo](https://meta.discourse.org/u/barreeeiroo)\
**Post date:** [2018年三月26日 22:51 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/63 "2018-03-26T22:51:00Z")

</div>

This is still showing me the 502 error page from Cloudflare:

 ![image](https://global.discourse-cdn.com/meta/original/3X/f/1/f105240f79c2b2b527b6b33ad91cf12fc209a924.png)

My NGINX config file:

```plaintext
server {
  listen 80; listen [::]:80; listen 443 ssl http2; listen [::]:443 ssl http2;
  server_name community.makeroid.io;

  client_max_body_size 0;

  location / {
    error_page 502 =502 /errorpages/discourse_offline.html;
    proxy_intercept_errors on;

    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 https;
  }

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

```

However this works:

> **[Whooops | Kodular Community](https://community.kodular.io/errorpages/discourse_offline.html)**

---

<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:** [2018年三月27日 04:06 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/64 "2018-03-27T04:06:52Z")

</div>

Are you sure that you followed the steps exactly? Can you post your `app.yml` file (with sensitive information redacted)? Did you rebuild after changing `app.yml`?

---

<div class="post-metadata">

**Author:** ![barreeeiroo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barreeeiroo/32/165264_2.png) [@barreeeiroo](https://meta.discourse.org/u/barreeeiroo)\
**Post date:** [2018年三月27日 09:23 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/65 "2018-03-27T09:23:37Z")

</div>

Yes, as I weren’t using let’sencrypt for SSL those lines where already commented, and then I commented too the ports expose  
And yes, I rebuilt after so

 ![juicessh](https://global.discourse-cdn.com/meta/original/3X/4/7/472471227440414da54d38b7840ff4c4cf5bed02.png)

---

<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:** [2018年三月27日 10:03 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/66 "2018-03-27T10:03:16Z")

</div>

Hm, in that case, I don’t see an obvious problem, and you’ll need to debug. What happens when you try this without Cloudflare?

---

<div class="post-metadata">

**Author:** ![barreeeiroo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barreeeiroo/32/165264_2.png) [@barreeeiroo](https://meta.discourse.org/u/barreeeiroo)\
**Post date:** [2018年三月27日 11:21 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/67 "2018-03-27T11:21:47Z")

</div>

It’s weird  
Without Cloudflare it works, it shows the custom page

Probably the response code is causing the conflict?

---

<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:** [2018年三月27日 11:23 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/68 "2018-03-27T11:23:02Z")

</div>

Maybe, I have no idea how Cloudflare handles that, exactly. Maybe someone else can help, or you can find an option for that in Cloudflare’s configuration? If that doesn’t work out, you could try contacting Cloudflare support 🙂

---

<div class="post-metadata">

**Author:** ![barreeeiroo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barreeeiroo/32/165264_2.png) [@barreeeiroo](https://meta.discourse.org/u/barreeeiroo)\
**Post date:** [2018年三月27日 11:23 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/69 "2018-03-27T11:23:59Z")

</div>

Fixed

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

Just changed the =502 to =200  
I supposed that as Cloudflare detected 502 response code they were showing their page  
I changed the response code to 200 and now it works

 ![chrome](https://global.discourse-cdn.com/meta/original/3X/0/9/096a284cd932743163c90420385b61092f936abb.png)

---

<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:** [2018年三月27日 11:25 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/70 "2018-03-27T11:25:51Z")

</div>

I wouldn’t call this _fixed_, though – you want to serve `502` here to tell browsers that this is an error condition.

---

<div class="post-metadata">

**Author:** ![barreeeiroo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barreeeiroo/32/165264_2.png) [@barreeeiroo](https://meta.discourse.org/u/barreeeiroo)\
**Post date:** [2018年三月27日 11:27 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/71 "2018-03-27T11:27:16Z")

</div>

Well, if you want to display a 502 page through Cloudflare you have to pay 😅

 ![chrome](https://global.discourse-cdn.com/meta/original/3X/2/4/2415be3680a4bd19cabed2f3cb59771216b10976.png)

---

<div class="post-metadata">

**Author:** ![cebe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cebe/32/119560_2.png) [@cebe](https://meta.discourse.org/u/cebe)\
**Post date:** [2018年十月3日 14:04 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/72 "2018-10-03T14:04:18Z")

</div>

It should be noted that running an nginx proxy in front of Discourse as described here will result in the rate limit, which is by default configured in Discourse Docker to apply for requests for all users.

The [rate limit template](https://github.com/discourse/discourse_docker/blob/ceffc4433e1bd6fcbd101f2427e17232fc99ab14/templates/web.ratelimited.template.yml) **templates/web.ratelimited.template.yml** should be removed from the docker config and the rate limit should then be configured in the outer nginx instance instead.

---

<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:** [2018年十月3日 15:53 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/73 "2018-10-03T15:53:46Z")

</div>

> [@cebe](#):
>
> It should be noted that running an nginx proxy in front of Discourse as described here will result in the rate limit, which is by default configured in Discourse Docker to apply for requests for all users.

Why is that? The inner Nginx should trust the forwarded source IP as per this line:

> <https://github.com/discourse/discourse_docker/blob/ceffc4433e1bd6fcbd101f2427e17232fc99ab14/templates/web.socketed.template.yml#L19>

---

<div class="post-metadata">

**Author:** ![cebe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cebe/32/119560_2.png) [@cebe](https://meta.discourse.org/u/cebe)\
**Post date:** [2018年十月3日 16:16 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/74 "2018-10-03T16:16:22Z")

</div>

The rate limit uses `$binary_remote_addr`, which seems to be not overwritten by `set_real_ip_from`.  
I also see that `$remote_addr` is shown as ´unix:` in the discourse nxing access.log.

IP adresses inside discourse itself seem to work (looking at IPs for user login).

---

<div class="post-metadata">

**Author:** ![cebe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cebe/32/119560_2.png) [@cebe](https://meta.discourse.org/u/cebe)\
**Post date:** [2018年十月3日 16:22 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/75 "2018-10-03T16:22:48Z")

</div>

Nginx requires the `X-Real-IP` header to be set for this to work properly!

> **[Module ngx\_http\_realip\_module](https://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header)**
>
> The ngx\_http\_realip\_module module is used to change the client address and optional port to those sent in the specified header field.

> Default: real\_ip\_header X-Real-IP;

So the following header needs to be added to the proxy (this is missing in your config above):

```
proxy_set_header X-Real-IP $remote_addr;

```

---

<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:** [2018年十月3日 16:35 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/76 "2018-10-03T16:35:03Z")

</div>

How certain are you that `X-Forwarded-For` is ignored by default? This guide isn’t particularly new, [this one](https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247) only sets `X-Forwarded-For` in the HTTP-only case, and I haven’t seen any complaints about rate limits hitting. Also, I’m operating a Discourse site behind such a Nginx proxy, and Discourse does see the real IP address.

If you’re certain, feel free to add the line above – it’s a wiki!

---

<div class="post-metadata">

**Author:** ![cebe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cebe/32/119560_2.png) [@cebe](https://meta.discourse.org/u/cebe)\
**Post date:** [2018年十月3日 16:38 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/77 "2018-10-03T16:38:40Z")

</div>

Nginx access logs show `unix:` as the client when I do not add the header. I get the correct IP when I add it. This also complies to what the nginx docs say so I am very certain this is how it works.

Discourse itself seems to evaluate the `X-Forwarded-For` header so the problem here only affects IP handling on the nginx which sits in the Discourse Docker container.

I updated the wiki post.

---

<div class="post-metadata">

**Author:** ![TheBestPessimist](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thebestpessimist/32/247704_2.png) [@TheBestPessimist](https://meta.discourse.org/u/TheBestPessimist)\
**Post date:** [2018年十月4日 04:49 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/78 "2018-10-04T04:49:26Z")

</div>

From what happened in my case i believe @cebe is right and you need `X-Real-IP` specifically for inner nginx.  
See [Discourse socketed: Nginx in front of discourse: no IP adresses](https://meta.discourse.org/t/discourse-socketed-nginx-in-front-of-discourse-no-ip-adresses/96382) for reference.

---

<div class="post-metadata">

**Author:** ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)\
**Post date:** [2019年五月24日 21:36 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/79 "2019-05-24T21:36:26Z")

</div>

Is this possible today? Right now our site goes down when doing an upgrade.

---

<div class="post-metadata">

**Author:** ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)\
**Post date:** [2019年五月24日 22:16 UTC](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238/80 "2019-05-24T22:16:04Z")

</div>

Yes, I use it without any issue.

[上一頁](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238.md?page=3)

[下一頁](https://meta.discourse.org/t/add-an-offline-page-to-display-when-discourse-is-rebuilding-or-starting-up/45238.md?page=5)
