Node.js的+防爆preSS:应用程序将无法启动侦听端口80 [英] Node.js + Express: app won't start listening on port 80

查看:164
本文介绍了Node.js的+防爆preSS:应用程序将无法启动侦听端口80的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建和推出一个这样的程序:

I create and launch an app like this:

express -s -t ejs
npm install express
npm install ejs
node app.js

和它的作品(3000端口)。但是,当我去更改端口为80,那么在运行节点app.js 输出这样的:

and it works (on port 3000). But when I go and change the port to 80, then running node app.js outputs this:

node.js:198
throw e; // process.nextTick error, or 'error' event on first tick
          ^
TypeError: Cannot call method 'getsockname' of null
at HTTPServer.address (net.js:746:23)
at Object.<anonymous> (/var/www/thorous/app.js:35:67)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.<anonymous> (module.js:470:10)
at EventEmitter._tickCallback (node.js:190:26)

这也工作在我的笔记本电脑,但不是我的Amazon EC2实例,其中80端口是开放的。 能找出什么是错的。任何提示?

This works too on my laptop, but not on my Amazon EC2 instance, where port 80 is open. Can figure out what's wrong. Any tips?

推荐答案

你开始你的应用程序的根?由于较低的端口号需要root权限。 也许须藤节点app.js的作品?

Are you starting your app as root? Because lower port numbers require root privileges. Maybe a sudo node app.js works?

但你不应该运行在80端口的任何Node.js的应用程序以root权限!从来没有!

BUT, you should NOT run any node.js app on port 80 with root privileges!!! NEVER!

我的建议是,在前面作为反向代理的nginx运行到您的Node.js应用程序的端口,例如运行3000

My suggestions is to run nginx in front as a reverse proxy to your node.js app running on port e.g. 3000

这篇关于Node.js的+防爆preSS:应用程序将无法启动侦听端口80的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆