connect() failed (111: Connection refused) while connecting to upstream

Hi all,

Today the node server was throwing a 502 Bad Gateway error, after checking the error file we have the following message:

2023/10/04 11:43:12 [error] 48367#48367: *24 connect() failed (111: Connection refused) while connecting to upstream, client: request: “GET /api HTTP/2.0”, upstream: “

We already checked the

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
October 5, 2023
Accepted Answer

Hi there,

The error message connect() failed (111: Connection refused) while connecting to upstream means that Nginx tried to pass a request to the upstream server but was unable to establish a connection.

This is most likely caused by one of those two things:

  1. Node Server Not Running: Ensure that the node server is running. Check the process:

    ps aux | grep node

    If it’s not running, you will have to start your app again. If it is running, check its logs for any errors and feel free to share them here.

  2. Port Misconfiguration: Ensure that the node server is running on port 8080, as Nginx is trying to forward requests to that port.

Here is also a quick video demo on how to troubleshoot this:



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel