Question

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: 188.27.129.65 request: “GET /api HTTP/2.0”, upstream: “http://127.0.0.1:8080/api

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:

Best,

Bobby

Try DigitalOcean for free

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

Sign up

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.