# 502 Bad Gateway，突然发生

**URL:** <https://meta.discourse.org/t/502-bad-gateway-suddenly/55956>\
**Category:** Self-hosting\
**Tags:** server-resources\
**Created:** [2017年一月18日 09:42 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956 "2017-01-18T09:42:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vereos](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vereos/32/66524_2.png) [@Vereos](https://meta.discourse.org/u/Vereos)\
**Post date:** [2017年一月18日 09:42 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/1 "2017-01-18T09:42:24Z")

</div>

Hello there.

Yesterday my Discourse forum was working fine: it’s more than one year that runs successfully on a Digital Ocean machine and I never had problems.

Before going to sleep yesterday, I checked my forum and all was fine. I wake up this morning and I get a 502 Bad Gateway error. I didn’t attempt to upgrade, and not even some kind of operation on the VM.

I mean… how is this even possible? I am clueless.

I tried to do a `./launcher restart app` but it didn’t help, so I ran a `./launcher rebuild app` and I get this:

> root@Forum:/var/discourse# ./launcher rebuild app  
> Ensuring launcher is up to date  
> Fetching origin  
> remote: Counting objects: 154, done.  
> remote: Total 154 (delta 67), reused 67 (delta 67), pack-reused 86  
> Receiving objects: 100% (154/154), 19.20 KiB | 0 bytes/s, done.  
> Resolving deltas: 100% (109/109), completed with 23 local objects.  
> From [GitHub - discourse/discourse\_docker: A Docker image for Discourse · GitHub](https://github.com/discourse/discourse_docker)  
> 12fa363..1f5042f master → origin/master

- [new branch] configurable-pg-sleep → origin/configurable-pg-sleep
- [new branch] launcher-env-vars → origin/launcher-env-vars
- [new branch] pg\_ctl → origin/pg\_ctl
- [new branch] user-args-for-last → origin/user-args-for-last  
Updating Launcher  
Updating 12fa363..1f5042f  
Fast-forward  
image/base/Dockerfile | 19 ++++++++±—  
image/base/VERSION | 2 ±  
image/base/install-imagemagick | 2 ±  
image/base/install-nginx | 2 ++  
image/build.rb | 2 ±  
image/discourse/Dockerfile | 4 ±-  
image/discourse\_bench/Dockerfile | 4 ±-  
image/discourse\_dev/Dockerfile | 12 +++++±-  
image/discourse\_dev/ensure-database | 2 ++  
image/discourse\_dev/postgres\_dev.template.yml | 41 +++++++++++++++++++++++++++  
image/discourse\_fast\_switch/Dockerfile | 4 ±-  
image/discourse\_test/Dockerfile | 4 ±-  
launcher | 8 ++±–  
templates/web.letsencrypt.ssl.template.yml | 5 +±-  
templates/web.template.yml | 2 ±  
15 files changed, 87 insertions(+), 26 deletions(-)  
create mode 100644 image/discourse\_dev/postgres\_dev.template.yml

> WARNING: We are about to start downloading the Discourse base image  
> This process may take anywhere between a few minutes to an hour, depending on your network speed

> Please be patient

> Unable to find image ‘discourse/discourse:1.3.10’ locally  
> 1.3.10: Pulling from discourse/discourse  
> ba66ef388b03: Pulling fs layer  
> 82f56b9b0da9: Pulling fs layer  
> 82f56b9b0da9: Verifying Checksum  
> 82f56b9b0da9: Download complete  
> ba66ef388b03: Verifying Checksum  
> ba66ef388b03: Download complete  
> Pulling repository [docker.io/discourse/discourse](http://docker.io/discourse/discourse)  
> Tag 1.3.10 not found in repository [docker.io/discourse/discourse](http://docker.io/discourse/discourse)  
> Your Docker installation is not working correctly

> See: [Troubleshoot docker installation issues](https://meta.discourse.org/t/docker-error-on-bootstrap/13657/18)

It looks like this error is Docker-related but I wouldn’t know how to solve it. Any help?

---

<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:** [2017年一月18日 10:34 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/2 "2017-01-18T10:34:45Z")

</div>

How much disk space, how much memory? Check memory and disk space. Disk space in particular gets used up over time..

---

<div class="post-metadata">

**Author:** ![Vereos](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vereos/32/66524_2.png) [@Vereos](https://meta.discourse.org/u/Vereos)\
**Post date:** [2017年一月18日 11:04 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/3 "2017-01-18T11:04:11Z")

</div>

You were right. Disk space was almost unexisting. I removed some old backups and now I have this:

> System load: 0.89  
> Processes: 111  
> Usage of /: 92.2% of 29.40GB  
> Memory usage: 83%  
> Swap usage: 29%  
> =\> / is using 92.2% of 29.40GB

The forum went online almost instantly after that. Thanks!

However, as you can see from the stats above, I’ll probably have the same problem in a while. What can I do to free disk space, apart from reducing the number of stored backups? I once had the _download remote images to local_ feature activated, but not anymore (since a few months, actually). Maybe I could delete something from there?

---

<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:** [2017年一月18日 11:17 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/4 "2017-01-18T11:17:07Z")

</div>

clean up old docker images

```
cd /var/discourse
./launcher cleanup

```

and clean up old Ubuntu updates

```
apt-get autoclean
apt-get autoremove

```

---

<div class="post-metadata">

**Author:** ![Vereos](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vereos/32/66524_2.png) [@Vereos](https://meta.discourse.org/u/Vereos)\
**Post date:** [2017年一月18日 16:39 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/5 "2017-01-18T16:39:04Z")

</div>

> [@codinghorror](#):
>
> apt-get autoclean  
> apt-get autoremove

Terminated successfully, but

> [@codinghorror](#):
>
> cd /var/discourse  
> ./launcher cleanup

Kept running for ~4h. At the end my ssh session with the VM terminated because of a network issue and I couldn’t see the output of the command (if there was one… for what I know, it might be still running).

However, from the Discourse dashboard I’m tracking the free space on the disk and it’s… _odd_.

![](https://global.discourse-cdn.com/meta/original/3X/d/4/d4c7817288675df0c3dcf9ccaa87ff091be3f596.png)

It says I have 261 MB free but this morning after deleting the backups I had more than 1 GB.

The `/var/discourse` directory is 4.3GB only. Could it be that something like the OS is downloading upgrades that I must apply to clear up space?

---

<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:** [2017年一月18日 22:28 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/6 "2017-01-18T22:28:00Z")

</div>

> [@Vereos](#):
>
> Kept running for ~4h. At the end my ssh session with the VM terminated

That is very very odd. Can you try again? @sam any reason this command wouldn’t execute?

---

<div class="post-metadata">

**Author:** ![Vereos](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vereos/32/66524_2.png) [@Vereos](https://meta.discourse.org/u/Vereos)\
**Post date:** [2017年一月19日 10:06 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/7 "2017-01-19T10:06:18Z")

</div>

Tried again some minutes ago and I got this

> WARNING: We are about to start downloading the Discourse base image  
> This process may take anywhere between a few minutes to an hour, depending on your network speed

> Please be patient

> Unable to find image ‘discourse/discourse:1.3.10’ locally  
> Repository [docker.io/discourse/discourse](http://docker.io/discourse/discourse) already being pulled by another client. Waiting.

Last time I ran the command, it tried to download the image and got stuck on a _Pull Complete_ message for hours. I guess it is still running.

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2017年一月19日 13:14 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/8 "2017-01-19T13:14:14Z")

</div>

> [@Vereos](#):
>
> Last time I ran the command, it tried to download the image and got stuck on a Pull Complete message for hours. I guess it is still running

Reboot your server. And then try again.

---

<div class="post-metadata">

**Author:** ![Vereos](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vereos/32/66524_2.png) [@Vereos](https://meta.discourse.org/u/Vereos)\
**Post date:** [2017年一月25日 11:59 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/9 "2017-01-25T11:59:04Z")

</div>

Rebooting the server worked, the `./launcher cleanup` command ran successfully! Thanks!

However, it only cleared 16 MB. ☹ Is there any other way to clear disk space?

On a sidenote, when I start my SSH session with the VM I read:

> 115 packages can be updated.  
> 64 updates are security updates.

> New release ‘16.04.1 LTS’ available.  
> Run ‘do-release-upgrade’ to upgrade to it.

And the `apt-get autoremove` command returns:

> Reading package lists… Done  
> Building dependency tree  
> Reading state information… Done  
> 0 upgraded, 0 newly installed, 0 to remove and 114 not upgraded.

Is there any chance that performing the upgrades will free disk space?

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2017年一月25日 15:38 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/10 "2017-01-25T15:38:01Z")

</div>

I think that you need a bigger disk. One way to save space is saving less backups, like only last 3 or 5, but looks like your forum is big enough that you need to move to a bigger machine.

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [2024年六月8日 12:45 UTC](https://meta.discourse.org/t/502-bad-gateway-suddenly/55956/11 "2024-06-08T12:45:02Z")

</div>

该主题在 2698 天后自动关闭。不再允许回复。
