Question

My Nodejs Backend ends is not accessible

I am new to digital ocean after following tutorials on deploy an mern stack application, i am serving the api and front the api, the frintend is working perfectly but the api isnt working below is my set nginx default setup

 location / {
                proxy_pass http://localhost:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
                }
        location /api {
    proxy_pass http://localhost:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;

i have also tried to log the error with this command sudo tail -30 /var/log/nginx/error.log

below is my response 2020/08/14 14:23:40 [error] 26741#26741: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 105.112.156.22, server: _, request: “GET /api/services HTTP/1.1”, upstream: “http://127.0.0.1:8000/api/services”, host: “164.90.231.19”

when i checked with “pm2 status” I discover my backend stop working after the first 30secs of restarting please can anyone help, I have been on this 2days ago


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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @adavidoladele,

Most probably there is some issue with your NodeJS backend code. Usually, when it stops after 30 seconds or at some point like that it’s because it hit code that it couldn’t execute thus failing. I’ll recommend checking out logs for your NodeJS app, try running it manually and not with the service pm2 to see if it loads and whether it would fail at some point.

All in all, from everything you’ve described, I can confirm it’s not an Nginx configuration issue but everything lies with your NodeJS app.

Regards, KFSYs