Reputation: 2297
I'm getting so frustrated... I can't find any information online to help me.
My setup is:
I've tried using my public DNS/public IP and restarting nginx, I've tried port 80, 8000, 1337, etc... I've tried deleting Nginx. ps aux | grep :3000
returns nothing. ps aux | grep :80
returns nothing. etc...
Here's the relevant code:
https.createServer(options, app).listen(app.get('port'), '127.0.0.1', function() {
console.log('Express server listening on port ' + app.get('port'));
});
http.createServer(function(req, res) {
res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
res.end();
}).listen(3000);
No matter which port I use, I get the same error for sudo node app.js
and node app.js
:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at net.js:1146:9
at dns.js:72:18
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
I did get this to work, but I need to redirect traffic to port 443 and use https:
app.listen(3000, '127.0.0.1', function() {
console.log('Express server listening on port ' + app.get('port'));
});
Upvotes: 3
Views: 2740
Reputation: 12159
According to my own experience (not on EC2) and also according to this comment by the OP, I would bet that the solution to this problem is to run the process as sudo
-- or, if you want, there must be a Linux group and permissions somewhere that prevents non-group users to attach processes to port 80 or 443, in which case running the process as a super user will do the job.
The fact that the OP delegated the job of attaching to the correct port to Nginx, and that Nginx is normally run as a super user process fits with this explanation.
Upvotes: 0
Reputation: 12399
You can use netstat -tulpn | grep :XX
, XX being the port you want to check.
It seems that you're trying to start both a http and a https server on the same port. delete the http.createServer bit and you'll be fine.
Upvotes: 4