Site responds 502 Bad gateway - is it Ruby?

AI-generated summary

Chris_Valentine reported a 502 Bad Gateway error after restarting their Discourse instance, suspecting Ruby/Rails as the cause. neounix confirmed Rails runs on port 3000 and suggested checking Rails logs. itsbhanusharma noted the issue may stem from improperly changing the domain name, recommending this guide. Chris later revealed a misconfiguration causing images to load from a development domain without a certificate, triggering cross-site security issues 4. Complicating matters, traffic routed through Cloudflare interfered with SSL certificates, prompting pfaffman to advise disabling Cloudflare temporarily for Let’s Encrypt to work. Ultimately, Chris confirmed the issue was resolved after rebuilding the container and successfully configuring Let’s Encrypt 7.

We have a Discourse that’s been running for at least three years and yesterday I made the mistake of restarting the instance in the hope it would take a domain change. The instance is running and we can see nginx is seeing requests form outside, but all visitors are getting “502 Bad gateway” all the time. Here’s an example entry in the nginx error log:

2020/06/22 19:03:26 [error] 11742#11742: *158 connect() failed (111: Connection refused) while connecting to upstream, client: 162.158.159.12, server: <my domain>, request: "GET                / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "<my domain>"

There’s no webserver running outside Docker so the app.yml file simply forwards 80 and 443 into the container. But what is supposed to be on port 3000? Is it suppose to be Ruby / Rails?

Hi Chris:

Yes, you are correct.

Rails runs on port 3000 in the Discourse app.

You might want to check the Rails log in the app to see if you can find out what is happening with Rails.

Hope this helps a little bit.

Were you trying to change the domain name for your instance?

There are procedures in place for that. if you don’t undertake the process, it can cause errors such as the one you’re experiencing.

Please follow this guide, it will help you change the domain name properly.
Change the domain name or rename your Discourse

There is a “development” alternative to the live domain and somehow that has sneaked into the configuration such that everything but the images comes from the live domain but the images are coming from the dev domain. As the latter doesn’t have a certificate, we (quite rightly) run into the cross-site security issue and the images don’t load.

We are currently trying to rebuild the container, as suggested elsewhere.

An additional complication is that all traffic is going through CloudFlare so we’re now having problems with SSL certificates. Note sure if templates/cloudflare.template.yml still works?

You’ll need to disable cloudflare to get let’s encrypt to be able I request a certificate

All sorted now. Our best tech managed to make a new build and has even got LetsEncrypt to work!