Web service returning HTTP/1.1 502 Bad Gateway

https://berry-rendering-service.onrender.com is returning HTTP/1.1 502 Bad Gateway error. However there is nothing suspicious in logs, server seems to be running.

curl http://localhost:3000/ in the shell works fine, so looks like Render problem.

Hi Vlad,

One of the ways in which we determine the HTTP port for a service is to send a HEAD request and wait for a response. It appears that the service in question is responding to HEAD requests in about 2.5 seconds. This is longer than our current threshold and hence the test request times out.

You can get around this issue by setting the PORT env var to the port number you’d like to listen on.( 3000 in this case)

1 Like

Where do I set the PORT variable? The render.yaml? I looked around and didn’t see it in the UI settings section or the documentation for blueprints. Or are you saying to add a:

envVar:
  - key: PORT
    value: 3000 # or 80, in my case

The yaml snippet you posted should work.

I’ve added a link to our env var docs as well Environment Variables | Render

1 Like

Hello! I’m experiencing the same issue with a Node app. I’ve tried all of the suggestions but I’m still getting a 502:

  • Set PORT env var
  • Confirmed service build succeeded
  • Confirmed server is running

Are there any other reasons 502s would be returned?

Hi @isugerman, welcome to the Render community! Can you let me know the name of the service you are having trouble with so I can take a look? Feel free to DM me.

Hi @tyler

Thanks for the response!

This turned out to be something internal w/Render which was quickly resolved over a support chat. That said - all of the other recommendations (port and 0.0.0.0 host) were also needed.

Sorry - I should have updated this post!

Hello,

I am in a similar position where I am receiving a 502 Bad Gateway error when trying to access the Express.js we service I am hosting: https://ahrq-cds-connect-cql-services.onrender.com/. I am not seeing any indication that a connection was made from the logs, and I have tried all of the suggestions mentioned here. Any help would be much appreciated.

Thank you!

Hey Mick,

I’ve reached out to you via the support ticket you opened. It looks like your app is your app host is starting on the IPv6 loopback “::1”, please change this to 0.0.0.0

Jérémy, Render Support

Hi,

I’m encountering the same problem. Mine happens intermittently. Like 4 out of every 10 requests in a row will return 502. I’ve followed the suggestions in this thread, but I’m still having the issue.

Thanks, this is solved by changing host from localhost to 0.0.0.0

Hello, I’m working on a MERN stack project; it’s a simple landing page. There’s a form on it that the user can fill out, and then we will receive it in our database. My code was working fine in localhost, but after I deployed it on your website, when I tried to make a ‘POST’ API call (fill out the form as a user), I got a 502 Bad Gateway error. I’ve tried many solutions, but nothing has happened.
this is my website: https://lvw.onrender.com/
This is the error:

Here’s my CORS access:

And here’s my Environment Variables