502 error on nginx

Hello,

I’ve just run ./launcher rebuild app with no apparent errors. But when I try to open the site, I get a 502 error.

The nginx error log (shared/standalone/log/var-log/nginx/error.log) shows:

2020/08/12 05:47:43 [error] 653#653: *7 connect() failed (111: Connection refused) while connecting to upstream, client: [...], server: _, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:3000/", host: "[...]"

I’ve checked all the topics I found about discourse and nginx 502 errors but couldn’t find or understand anything that makes sense for my case.

This might be relevant, running from the container:

# netstat -plant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      644/nginx: master p 
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      644/nginx: master p 
tcp6       0      0 :::6379                 :::*                    LISTEN      -                   
tcp6       0      0 :::5432                 :::*                    LISTEN      -

Is there something that should be running in port 3000?

Could you please guide me on where to look for more information to debug this problem?

pura vida :slight_smile:

It shows 502 initially as the services inside the container are starting up. It should go away within 30 seconds. If it doesn’t it is possible that your server’s CPU is under extreme load and it is causing slowdown.

3 Likes

Thanks @itsbhanusharma.

I’ve run ./launcher restart app and monitored the load with top, and it’s well under 10%.

I think the CPU should be enough to handle the load:

$ cat /proc/cpuinfo  | grep 'name' | uniq
model name      : Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz
$ cat /proc/cpuinfo  | grep process | wc -l
4

Is there a better way to debug the start up of the container?
Any other ideas?

1 Like

Which plugins are installed? Is this server on SSD?

I’ve just cloned the repository and run the setup commands, so I guess it just has the default plugins? Not sure where to check, but I’m sure I’ve added none.

The server is not SSD.

Hey @elopio

Maybe you can post your ‘yml‘ file without any sensitive info?

Sure, it’s here:

https://paste.ubuntu.com/p/k7yR42q2vF/

Discourse requires SSD, normal spinning drives don’t deliver sufficient IOPS.

And is that the cause for the 502 error? Or without an SSD should I see the website working, but very slow?

Using a traditional hard drive versus an SSD drive should not cause a 502 error. That’s not really plausible, as your question indicates @elopio.

Here is a little writeup which might be helpful:

The best thing to do, in my view, is to open up some terminals and run tail -f on your both your Rails and nginx log files, including the error logs and access logs; and then try to access and make sure when you see the 502 error you have your eyes on the tails of the log files.

Do you know where those logfiles reside and how to run tail -f commands on them in terminals?


Note, you asked earlier:

Rails run on port 3000 inside the Docker container and that port is not exposed outside the container. That is why you are not seeing port 3000 outside the container when you run netstat outside the container.

HTH

Speaking from experience slow IO absolutely can and does cause timeouts and a 502 error.

SSD-level IOPS are a firm requirement.

Wooo, looking at the rails logs I found that the unicorn log was huge, complaining about some permission errors. I deleted rm -rf tmp/cache/bootsnap-compile-cache/, and now I see the congratulations screen!!!

Thank you friends. I’ll play with this a little more before deciding to recreate it in an SSD server.

4 Likes

You are welcome @elopio

Glad you found the problem in the logs and you sorted this out. Well done.

Wishing you smooth sailing ahead!

1 Like

Ok, this is working brilliantly. I want to show what we are doing:

It’s the migration of the Costa Rican hackerspace from Telegram to Discourse :slight_smile: We still have to do sooo many things, but this time I’m sure we’ll be able to get rid of the chat for sure. Thanks a lot discourse people!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.