# 502 bad gateway

**URL:** <https://meta.discourse.org/t/502-bad-gateway/292930>\
**Category:** Self-hosting\
**Created:** [January 25, 2024, 4:22pm UTC](https://meta.discourse.org/t/502-bad-gateway/292930 "2024-01-25T16:22:39Z")\
**Posts on this page:** 5\
**Page:** 1

## AI-generated summary

In a thread titled "502 bad gateway" under the Installation category, [stokedcrf](/t/-/292930/1) reported encountering a 502 error after a possible Discourse update, despite running `./launcher rebuild app` and `./discourse-setup`, both of which failed. Seeking help, [stokedcrf](/t/-/292930/1) shared a log snippet showing a failure during `db:migrate`, with PostgreSQL shutting down unexpectedly. [JammyDodger](/t/-/292930/2) encouraged sharing full logs to diagnose the issue, while [Firepup650](/t/-/292930/4) advised reviewing earlier error messages in the log. Ultimately, [stokedcrf](/t/-/292930/5) resolved the problem by performing a fresh install and restoring from a backup, confirming everything is now working. The thread highlights common troubleshooting steps for Docker-based Discourse installations encountering database migration or bootstrapping failures.

<div class="post-metadata">

**Author:** ![stokedcrf](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stokedcrf/32/351173_2.png) [@stokedcrf](https://meta.discourse.org/u/stokedcrf)\
**Post date:** [January 25, 2024, 4:22pm UTC](https://meta.discourse.org/t/502-bad-gateway/292930/1 "2024-01-25T16:22:39Z")

</div>

Good morning everyone!

About a week ago my installation of Discourse may have updated. I’m not 100% sure, but all I know is whenever I would visit the site I’d get a 502 error issued by nginx.

This was your typical docker install.

I have since went in and ran “./launcher rebuild app” and it seemed to error out.

I then ran “./discourse-setup” and it errored out as well.

I’m no pro though and fairly new to discourse so I can post the results of the rebuild here if required.

After about a week of searching around and trying to find fix, I may just go ahead and do a complete fresh install on the VPS. That said, I’m not sure how to backup and restore the user accounts and databases.

Any advice would be amazing!  
Thank you for your time!

---

<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:** [January 25, 2024, 4:26pm UTC](https://meta.discourse.org/t/502-bad-gateway/292930/2 "2024-01-25T16:26:58Z")

</div>

Hello and welcome @stokedcrf 🙂

If you include the logs of your rebuild we may be able to pinpoint what the issue is. 🤞

---

<div class="post-metadata">

**Author:** ![stokedcrf](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stokedcrf/32/351173_2.png) [@stokedcrf](https://meta.discourse.org/u/stokedcrf)\
**Post date:** [January 29, 2024, 6:47pm UTC](https://meta.discourse.org/t/502-bad-gateway/292930/3 "2024-01-29T18:47:03Z")

</div>

Sorry for the delay.

While the rebuild log seems quite long, it seems this is around when it fails:

```plaintext
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)
I, [2024-01-29T18:40:10.599024 #1] INFO -- :
I, [2024-01-29T18:40:10.627958 #1] INFO -- : Terminating async processes
I, [2024-01-29T18:40:10.629723 #1] INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main pid: 42
2024-01-29 18:40:10.630 UTC [42] LOG: received fast shutdown request
2024-01-29 18:40:10.644 UTC [42] LOG: aborting any active transactions
2024-01-29 18:40:10.651 UTC [42] LOG: background worker "logical replication launcher" (PID 51) exited with exit code 1
2024-01-29 18:40:10.654 UTC [46] LOG: shutting down
2024-01-29 18:40:10.811 UTC [42] LOG: database system is shut down

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 3290 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
bootstrap failed with exit code 1
**FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
963d90233930c09a993e084bf1e858d7486ddb797bd5743e6073f4563db0777a

```

---

<div class="post-metadata">

**Author:** ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)\
**Post date:** [January 29, 2024, 8:57pm UTC](https://meta.discourse.org/t/502-bad-gateway/292930/4 "2024-01-29T20:57:04Z")

</div>

Please do as that log says and:

> [@stokedcrf](#):
>
> ```plaintext
> please scroll up and look for earlier error messages, there may be more than one.
> 
> ```

---

<div class="post-metadata">

**Author:** ![stokedcrf](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stokedcrf/32/351173_2.png) [@stokedcrf](https://meta.discourse.org/u/stokedcrf)\
**Post date:** [January 29, 2024, 9:36pm UTC](https://meta.discourse.org/t/502-bad-gateway/292930/5 "2024-01-29T21:36:32Z")

</div>

Thanks for all the tips folks.  
I ended up just doing a fresh install and restoring a backup from the backup directory. All is well! 🙂
