Question

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

Posted January 9, 2021 4.1k views
Nginx

Adding common proxy_pass to another container on server and getting this error (in title).
Found some issues, but it seems they doesn’t help me. :(
Backend is on 8080 port
netstat -plant

tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      528/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      681/sshd: /usr/sbin 
tcp        0      0 138.68.24.18:22         112.85.42.67:55747      ESTABLISHED 108245/sshd: root [ 
tcp        0      0 138.68.24.18:22         5.19.1.53:2686          ESTABLISHED 106286/sshd: root@p 
tcp        0    340 138.68.24.18:22         5.19.1.53:2604          ESTABLISHED 108038/sshd: root@p 
tcp        0      0 138.68.24.18:22         5.19.1.53:2471          ESTABLISHED 105166/sshd: root@p 
tcp6       0      0 :::80                   :::*                    LISTEN      107898/docker-proxy 
tcp6       0      0 :::8080                 :::*                    LISTEN      93312/docker-proxy  
tcp6       0      0 :::22                   :::*                    LISTEN      681/sshd: /usr/sbin 
tcp6       0      0 :::443                  :::*                    LISTEN      107887/docker-proxy 
tcp6       0      0 :::8000                 :::*                    LISTEN      1232/docker-proxy   
tcp6       0      0 :::9000                 :::*                    LISTEN      1220/docker-proxy   

Nginx config

server {
    listen              443 ssl http2;
    listen              [::]:443 ssl http2;
    server_name         hiddendomain.com www.hiddendomain.com;
    root                /var/www/hiddendomain.com/public;

    # SSL
    ssl_certificate     /etc/nginx/ssl/hiddendomain.com.crt;
    ssl_certificate_key /etc/nginx/ssl/hiddendomain.com.key;

    # security
    include             nginxconfig.io/security.conf;

    # index.html fallback
    location / {
        try_files $uri $uri/ /index.html =400;
    }

    location /api {
        proxy_pass http://0.0.0.0:8080/;
    }

    # additional config
    include nginxconfig.io/general.conf;
}

# HTTP redirect
server {
    listen      80;
    listen      [::]:80;
    server_name .hiddendomain.com;
    return      301 https://hiddendomain.com$request_uri;
}

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there @usapharmacydashboard,

It looks like there might be something wrong with the container itself. I would recommend checking your Docker container logs to see if there are any errors in there which could point you to the right direction.

To check the logs of the container, first find your container ID:

docker ps -a

And then use the following command:

docker logs container_id

On another note, what I could suggest is setting your proxy_pass rule to http://127.0.0.1:8080/ rather than 0.0.0.0.

You can also take a look at this quick video with some tips on how to troubleshoot that kind of errors:

Regards,
Bobby