Reputation: 1
I started pm2 server on my server running ubuntu 20.
To simplify the problem, I created a hello world app using node, like this (/var/www/html/pip/exampleserver.js):
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, '0.0.0.0');
console.log('Server running at http://0.0.0.0:3000/');
After starting the server with 'pm2 start exampleserver.js', the server is started, and it works fine when I access it from localhost :
wget -qO- localhost:3000
Result : "Hello World"
But I get ERR_CONNECTION_REFUSED when accessing the page from another computer on the same network (from http://10.200.96.23:3000, either from browser or command line)
However, when I change the script to listen to port 80 and restart pm2, it works just fine from the other computer (from http://10.200.96.23). It shows the result "Hello World".
Here is the result of netstat and ufw status that i've disabled in advance : netstat and ufw status
Screenshot of error connection refused : ERR_CONNECTION_REFUSED
I tried other ports, but nothing works other than 80. I don't want to run this server on port 80. What could be the problem?
Upvotes: 0
Views: 3798
Reputation: 47
Port 80 is open by default but not for other ports.
@aRvi is correct, you might need to open port 300 for that to be accessible.
Also pm2 monitor
will help you see code errors and monitor your application.
This saves my day many times when debugging my codes in PM2
Upvotes: 1
Reputation: 10601
First run
pm2 list
and delete the processes with
pm2 delete [ID]
Define a new ufw rule
ufw allow 3000/tcp
and run your application again.
Upvotes: 0