19

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";
    }
}
slm
  • 7,615
  • 16
  • 56
  • 76
Tam2
  • 293
  • 1
  • 2
  • 4
  • 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 '15 at 04:59

2 Answers2

23

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;
}
...
Christopher Perrin
  • 4,811
  • 19
  • 33
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;
}