Question

Connection Refused Issues

Just started having issues where my website is unable to pull data from my API hosted on digital ocean. We use cloudflare to proxy the server but keep getting these errors:

Ngix server error logs:

2024/07/04 23:59:57 [error] 15618#15618: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 172.11.111.111, server: api.website.com, request: "GET /findata/latestPrices HTTP/1.1", upstream: "http://127.0.0.1:3355/latestPrices", host: "api.website.com", referrer: "https://plex.website.com/"
2024/07/04 23:59:39 [error] 15617#15617: *377 no live upstreams while connecting to upstream, client: 172.22.222.22, server: api.website.com, request: "GET /findata/liveCandles?symbol=TSLAUSD&interval=1h HTTP/1.1", upstream: "http://localhost/liveCandles?symbol=TSLAUSD&interval=1h", host: "api.website.com", referrer: "https://info.website.com/"

IP and Website changed for privacy

Here is the current Nginx Setup:

server {
  server_name api.website.com;
  listen 80;
  listen [::]:80;

  location ^~ /values {
    rewrite ^/values/(.*)$ /$1 break;
    proxy_pass http://localhost:5001/;
  }

  location ^~ /lights {
    rewrite ^/lights/(.*)$ /$1 break;
    proxy_pass http://localhost:8008/;
  }

  location ^~ /plex {
    rewrite ^/plex/(.*)$ /$1 break;
    proxy_pass http://localhost:3007/;
  }

  location ^~ /number {
    rewrite ^/number/(.*)$ /$1 break;
    proxy_pass http://localhost:3009/;
  }

  location ^~ /findata {
    rewrite ^/findata/(.*)$ /$1 break;
    proxy_pass http://localhost:3355/;
  }

  location /ws/ {
    proxy_pass http://localhost:3355/ws;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
  }
}

Any insight or ideas?


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.

alexdo
Site Moderator
Site Moderator badge
July 5, 2024

Heya,

What you can do is to verify that the services (on ports 5001, 8008, 3007, 3009, and 3355) are running.

sudo netstat -tulnp | grep -E '5001|8008|3007|3009|3355'

If the services are managed by systemd, check their status:

sudo systemctl status service_name

Note: Replace service_name with the name of the service managing your application.

Additionally, ensure the Nginx configuration for syntax errors.

sudo nginx -t

And of course check the logs of your applications running on the specified ports for any errors that might be causing them to crash or not start properly.

Regards

KFSys
Site Moderator
Site Moderator badge
July 5, 2024

Heya,

Whenever you see an connect() failed (111: Connection refused) while connecting to upstream, client: 172.11.111.111, server: api.website.com, request: "GET /findata/latestPrices HTTP/1.1", upstream: "http://127.0.0.1:3355/latestPrices", host: "api.website.com", referrer: "https://plex.website.com/" error it almost always means that there is something wrong with your Application rahter than Nginx. As such, check your application logs and you’ll find the exact source of the problem.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel