NodeJs website hosted on AWS linux is not accessible

半腔热情 提交于 2019-12-12 03:08:49

问题


I hosted my NodeJs website on AWS Red Hat Linux but it's accessible from outside. although when i run my nodejs server from putty, it was running just fine.

below is my server creation code in nodejs.I'm using express framework with jade.

app.listen(80, function () {
    console.log('Server starts on port: ' + 80);
});

I have opened all traffic from AWS console also and tried other ports as well.

ps -ef | grep node says:-

and app.log says:-

uncaughtException: Error: listen EADDRINUSE
Server starts on port: 80

回答1:


You are getting this error as there is already a application that is using port 80 on your system, probably Apache or Nginx, so you should just use another port and configure your web-server to forward all HTTP requests to your port or just stop the webserver, also to use port 80 you need to use sudo so your commmand will be sudo node app.js. If you want to check what application is running on port 80 just use following commmand :

sudo netstat -tupln | grep 80

the output should show you what process is using your port you can kill it if you want




回答2:


app.listen(80,"0.0.0.0", function () {
console.log('Server starts on port: ' + 80);
});``

it should work always make sure your app is accessible over the network eg "0.0.0.0" parameterenter code here



来源:https://stackoverflow.com/questions/40779478/nodejs-website-hosted-on-aws-linux-is-not-accessible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!