15

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";
    }
}
  • 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 4:59
18

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;
}
...
  • To those who are confused, change localhost to 127.0.0.1 – kouton Jan 12 '15 at 16:13
  • Any ideas if I have 127.0.0.1 instead of localhost and this keeps happening? – Ken May 14 '15 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. – Christopher Perrin May 14 '15 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 – Robbie Averill Jan 25 '16 at 23:28
  • @RobbieAverill nice to hear that this answer is still helpful – Christopher Perrin Jan 26 '16 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.