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
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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.