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

nginxnode.js

I keep seeing the below error message's in the error log, I can access all of the resources but I'm unsure as to why the error is flagging.

error:

[error] 13368#0: *449 connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: myserver.com,
request: "GET /stories/mine HTTP/1.1", upstream:
"http://[::1]:5000/stories/mine", host: "myserver.com"

My Nginx config

I'm passing the connection over to a node.js cluster running on port 5000. Can't see what I would have missed?

upstream api {
    server localhost:5000;
}

server {
    listen 80; 
    server_name myserver.com;
    root /home/user/_api;


# Logging 

error_log /home/user/log/api.error.log notice;
    location / {
        proxy_redirect off;
        proxy_set_header   X-Real-IP            $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host                   $http_host;
        proxy_set_header   X-NginX-Proxy    true;
        proxy_set_header   Connection "";
        proxy_cache one;
        proxy_cache_key sfs$request_uri$scheme;
        proxy_pass         http://api;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Best Answer

Nginx connects to nodjs on the IPv6 loopback [::1]. nodejs is probably just listening on IPv4.

Try setting

upstream api {
    server 127.0.0.1:5000;
}
...