Report this

What is the reason for this report?

GET http://localhost:5000/user net::ERR_CONNECTION_REFUSED when running application

Posted on August 4, 2021

I’ve been following https://marketplace.digitalocean.com/apps/nodejs?getting-started tutorial to host my web application on the Droplet/IP I have.

I’ve been able to have the front end of my website successfully load however the backend with the HTTP requests are not working. I keep getting a 'GET http://localhost:5000/user net::ERR_CONNECTION_REFUSED' error. I’m using React for the frontend and Node for the backend.

This is the error I get from /var/log/nginx/error.log:

2021/08/04 03:03:58 [error] 20156#20156: *17 connect() failed (111: Connection refused) while connecting to upstream, client: 173.72.3.10, server: workoutlabnode, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3000/favicon.ico", host: "161.35.100.44", referrer: "http://161.35.100.44/login"
2021/08/04 03:05:15 [error] 20156#20156: *65 connect() failed (111: Connection refused) while connecting to upstream, client: 173.72.3.10, server: workoutlabnode, request: "GET /login HTTP/1.1", upstream: "http://127.0.0.1:3000/login", host: "161.35.100.44"
2021/08/04 03:11:08 [error] 20156#20156: *301 connect() failed (111: Connection refused) while connecting to upstream, client: 173.72.3.10, server: workoutlabnode, request: "GET /login HTTP/1.1", upstream: "http://127.0.0.1:3000/login", host: "161.35.100.44", referrer: "http://161.35.100.44/login"
2021/08/04 03:13:11 [error] 20156#20156: *346 connect() failed (111: Connection refused) while connecting to upstream, client: 173.72.3.10, server: workoutlabnode, request: "GET /login HTTP/1.1", upstream: "http://127.0.0.1:3000/login", host: "161.35.100.44", referrer: "http://161.35.100.44/workout-tracker"
2021/08/04 03:48:15 [alert] 20156#20156: *457 open socket #16 left in connection 7
2021/08/04 03:48:15 [alert] 20156#20156: *458 open socket #15 left in connection 9
2021/08/04 03:48:15 [alert] 20156#20156: aborting

This is my netstat -plant output:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      22722/nginx: master 
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      624/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      975/sshd: /usr/sbin 
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      22644/node          
tcp        0      0 161.35.100.44:80        173.72.3.10:59033       ESTABLISHED 22723/nginx: worker 
tcp        0      0 127.0.0.1:35252         127.0.0.1:3000          ESTABLISHED 22723/nginx: worker 
tcp        0      0 127.0.0.1:3000          127.0.0.1:35252         ESTABLISHED 22644/node          
tcp        0    340 161.35.100.44:22        173.72.3.10:55528       ESTABLISHED 16951/sshd: root@pt 
tcp6       0      0 :::5000                 :::*                    LISTEN      22688/node /root/wo 
tcp6       0      0 :::80                   :::*                    LISTEN      22722/nginx: master 
tcp6       0      0 :::22                   :::*                    LISTEN      975/sshd: /usr/sbin

This is part of my /etc/nginx/sites-available/default file:

location / {
                proxy_http_version 1.1;
                proxy_cache_bypass $http_upgrade;

                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;

                proxy_pass http://localhost:3000;
        }

        location /server {
                proxy_http_version 1.1;
                proxy_cache_bypass $http_upgrade;

                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;

                proxy_pass http://localhost:5000;
}

The frontend react app is supposed to be running on port 3000 and the backend server is running on port 5000.

Any help on how to solve this issue would be greatly appreciated!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.