Connection refused when running rhodecode through nginx

John asked:

Instead of seeing the rhodecode page when visiting repo.xxx.com I get a 502 (Bad Gateway).

Here is the nginx error.log entry.

2013/03/14 21:48:33 [error] 11207#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 11.111.111.11, server: repo.xxx.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "repo.xxx.com"

Here is the relevant portion of my nginx.conf.

upstream rhodecode{
        server 0.0.0.0:5000;
}

server {
        listen 80 default;
        server_name www.xxx.com;

        location / {
                root /opt/html;
                index index.html;
        }
}

server {
        listen 80;
        server_name repo.xxx.com;

        proxy_redirect              off;
        proxy_set_header            Host $host;
        proxy_set_header            X-Url-Scheme $scheme;
        proxy_set_header            X-Host $http_host;
        proxy_set_header            X-Real-IP $remote_addr;
        proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header            Proxy-host $proxy_host;
        client_max_body_size        400m;
        client_body_buffer_size     128k;
        proxy_buffering             off;
        proxy_connect_timeout       7200;
        proxy_send_timeout          7200;
        proxy_read_timeout          7200;
        proxy_buffers               8 32k;

        location / {
                try_files $uri @rhodecode;
        }

        location @rhodecode {
                proxy_pass http://rhodecode;
        }

}

I also changed the host property in my rhodecode ini file to be host=0.0.0.0. This is all being done on a ubuntu 12.04 LTS server hosted by linode (if that matters).

Most of what I’ve been reading would suggest that it is a “permissions” issue with ports not being opened up correctly or somehow my loopback interfaces aren’t configured correctly.

Here is the output of iptables -L -n.

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

My answer:


The problem is here:

upstream rhodecode{
        server 0.0.0.0:5000;
}

You didn’t specify a valid address for nginx to connect to; 0.0.0.0 is not a valid destination IP address.

To resolve the issue, specify the actual IP address, such as 127.0.0.1.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.