20

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";
    }
}
1
  • It's 2015 and i'm having this same problem. everytime a websocket message gets dropped this error appears in the log.
    – r3wt
    Apr 25, 2015 at 4:59

2 Answers 2

25

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;
}
...
6
  • To those who are confused, change localhost to 127.0.0.1
    – kouton
    Jan 12, 2015 at 16:13
  • Any ideas if I have 127.0.0.1 instead of localhost and this keeps happening?
    – Ken
    May 14, 2015 at 17:26
  • 3
    You should check if the service is listening. Try sudo netstat -pantu and look if the service is actually listening on the port. May 14, 2015 at 17:29
  • 1
    @ChristopherPerrin thanks for that advice. It helped me to realise that one of my pools wasn't listening on its port, and it turned out to be because another pool configuration was re-using the same name so overwriting its configuration
    – scrowler
    Jan 25, 2016 at 23:28
  • @RobbieAverill nice to hear that this answer is still helpful Jan 26, 2016 at 0:12
0

I got the same error. I am using docker. I found that the reason was that I used 127.0.0.1 but had to use name of my docker container. Here is the example:

This is a snippet from my nginx config file and this was the reason was getting an error ...failed (111: Connection refused) while connecting to upstream...:

location / {
    proxy_pass http://127.0.0.1:5006;
}

And this is what I use not and do not get this error anymore (a snippet from my nginx config). app-ui here is the name of my docker container with a React app:

location / {
    proxy_pass http://app-ui:5006;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .