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

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 *               LISTEN      528/systemd-resolve 
tcp        0      0    *               LISTEN      681/sshd: /usr/sbin 
tcp        0      0      ESTABLISHED 108245/sshd: root [ 
tcp        0      0          ESTABLISHED 106286/sshd: root@p 
tcp        0    340          ESTABLISHED 108038/sshd: root@p 
tcp        0      0          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;
    root                /var/www/;

    # SSL
    ssl_certificate     /etc/nginx/ssl/;
    ssl_certificate_key /etc/nginx/ssl/;

    # security
    include   ;

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

    location /api {

    # additional config

# HTTP redirect
server {
    listen      80;
    listen      [::]:80;
    return      301$request_uri;

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

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 rather than

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

Regards, Bobby