Home > Software engineering >  (111: Connection refused) while connecting to upstream, client: xxx server: xxx
(111: Connection refused) while connecting to upstream, client: xxx server: xxx

Time:01-19

i have a nextjs app hosted on nginx and im trying to get revalidate to work since it doesn't work(i have a question for that too) and someone in a discord suggested checking the nginx error log and i found this error:

2023/01/15 14:45:37 [error] 27467#27467: *1706 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xxx.xxx.xxx, server: kickz.rendives.nl, request: "GET /_next/static/chunks/webpack-69bfa6990bb9e155.js HTTP/1.1", upstream: "http://[::1]:8000/_next/static/chunks/webpack-69bfa6990bb9e155.js", host: "kickz.rendives.nl", referrer: "https://kickz.rendives.nl/products"

I tried setting

listen 8000;

in my conf file and i also tried changing my proxy_pass to:

proxy_pass https://xx.xxx.xxx.xxx:8000

instead of

proxy_pass http://localhost:8000

but that didn't work sadly. This is my kickz.rendives.nl.conf file:

server {
  server_name kickz.rendives.nl www.kickz.rendives.nl;

  location / {
    proxy_pass http://localhost:8000;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $host;
    add_header Cache-Control "no-store, must-revalidate";
  }

  location /products {
    proxy_pass http://localhost:8000;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_pragma;
    proxy_cache_revalidate on;
    add_header Cache-Control "no-store, must-revalidate";
    proxy_cache_lock on;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Cache-Control "no-cache";
  }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/kickz.rendives.nl/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/kickz.rendives.nl/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = www.kickz.rendives.nl) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = kickz.rendives.nl) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

  server_name kickz.rendives.nl www.kickz.rendives.nl;
    listen 80;
    return 404; # managed by Certbot

}

how can i get rid of the error? Also do you think this has something to do with the fact that revalidate doesn't work? Because my site works fine, i don't get any errors on the site itself.

CodePudding user response:

For anyone struggling with the same issue, i solved it by replacing the

proxy_pass http://localhost:8000;

with

proxy_pass http://127.0.0.1:8000;

Now i don't get the error anymore and everything works fine.

  • Related