during Nginx hosting (nodejs) pm2 status ocured error - node.js

during hosting when uploading my website by cloning git and added to the nginx but when starting the server by using the command PM2 START SERVER.JS it shows status as error
during hosting when uploading my website by cloning git and added to the nginx but when starting the server by using the command PM2 START SERVER.JS it shows status as error

Related

nginx.conf for NodeJS/React App returning 502 and 405

Trying to setup a staging environment on Amazon LINUX EC2 instance and migrate from Heroku.
My repository has two folders:
Web
API
Our frontend and backend are running on the same port in deployment
In dev, these are run on separate ports and all requests from WEB and proxied to API
(for ex. WEB runs on PORT 3000 and API runs on PORT 3001. Have a proxy set up in the package.json file in WEB/)
Currently the application deployment works like this:
Build Web/ for distribution
Copy build/ to API folder
Deploy to Heroku with web npm start
In prod, we only deploy API folder with the WEB build/
Current nginx.conf looks like this
Commented out all other attempts
Also using PM2 to run the thread like so
$ sudo pm2 bin/www
Current thread running like so:
pm2 log
This is running on PORT 3000 on the EC2 instance
Going to the public IPv4 DNS for instance brings me to the login, which it's getting from the /build folder but none of the login methods (or any API calls) are working.
502 response example
I have tried a lot of different configurations. Set up the proxy_pass to port 3000 since thats where the Node process is running.
The only response codes I get are 405 Not Allowed and 502 Bad Gateway
Please let me know if there is any other information I can provide to find the solution.
It looks like you don't have an upstream block in your configuration. Looks like you're trying to use proxy-pass to send to a named server and port instead of a defined upstream. There's is an example on this page that shows how you define the upstream and then send traffic to it. https://nginx.org/en/docs/http/ngx_http_upstream_module.html
server backend1.example.com weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;
server backup1.example.com:8080 backup;
server backup2.example.com:8080 backup;
}
server {
location / {
proxy_pass http://backend;
}
}````
Turns out there was an issue with express-sessions being stored in Postgres.
This led me to retest the connection strings and I found out that I kept receiving the following error:
connect ECONNREFUSED 127.0.0.1:5432
I did have a .env file holding the env variables and they were not being read by pm2.
So I added this line to app.js:
const path = require("path");
require('dotenv').config({ path: path.join(__dirname, '.env') });
then restarted the app with pm2 with the following command:
$ pm2 restart /bin/www --update-env

Deploy node.js in hostinger VPS but not running

I have my node app upload into hostinger and npm start run well.
But I still can't access http://my-ip:3000
node and npm and mysql have been installed
but no luck.
Am I missing some important steps?
this problem could come from your code || network
pm2 logs
see if there are some error logs
check on vps that if your service online
curl http://127.0.0.1:3000
if no resposne, you should fix the service code
check if your service runs on the right port
netstat -an | grep 3000

Unable to fix NGINX 502: Bad Gateway error on a Digital Ocean droplet - Ubuntu 20.04

I have deployed my website to a Digital Ocean droplet (Ubuntu 20.04 server).
Everything was working fine. Today, I did some changes to the website in my local machine. So I pushed the changes to GitHub and then cloned the GitHub repo again to the server. Then, I installed the dependencies and restarted PM2.
Now, when I visit my site https://sundaray.io, I get the following error.
The following is the error log.
How can I fix the error?
Simple meaning is
No HTTP server response, your Node Http server is not answering requests.
502 gateway mean server and Nginx is getting your request but there is issue with upstream.
you can use the command to show the logs of pm2
pm2 show
the application might be crashing or internal server 500 error.

Heroku Deployment 404 Error with Node.js and Express.js Server

Anyone willing to help with a Heroku Deployment?
When I run my local repo the server works great but once I deploy it on Heroku I get a 404 Error.
I am using Node.js Express Server.
The server console is suppose to generate: Listening on port 5000!
The error I get instead is: {"error":{"message":"Error not found in app.js"}}
Git Hub Repo
https://github.com/instant-help/instant-help-backend
Deployed Repo
https://thawing-river-10076.herokuapp.com/

PM2 and Nginx: 502 Bad Gateway

I've been trying to deploy my Node project on a brand new DO droplet, but i'm having some problems with PM2.
My steps are a follows:
Node came installed on the Droplet image (Ubuntu, Node v4.4.4)
Installed PM2 globally
Setup Nginx to reverse proxy 127.0.0.1:3000
Cloned my project and did npm install
All i get is Nginx complaining about a 502 Bad Gateway.
If i look at the Nginx error.log i get this:
connect() failed (111: Connection refused) while connecting to
upstream, client: client.ip, server: my.server, request:
"GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host:
"my.server"
PM2 doesn't have much to say about anything. Nothing in pm2 logs and status is online.
I tried skipping PM2 and just doing npm start which worked perfectly. I also tried setting up a dummy hello world application instead, and using that with PM2 - it also worked.
So this is currently where i'm at:
My project + PM2: doesn't work.
My project without PM2: works.
Hello World app + PM2: works.
I'm not really sure where to go from here.. I could just skip PM2 and use node, but i do want the features of PM2.
Any ideas?
I just had to start PM2 with bin/www instead of app.js. Express generator and everything...
Nginx has a directive called proxy_read_timeout which defaults to 60 secs. It determines how long nginx will wait to get the response to a request. In nginx. conf file, setting proxy_read_timeout to 120 secs solved our problem.
In my case I renamed app.js to project.js or something and it works.
This is some issue with the node installation. Delete the node_modules folder, install again using npm and start the project using pm2.
pm2 kill
rm -rf node_modules
npm i
pm2 start bin/www

Resources