即使没有其他进程阻塞该端口,Node.js 应用程序也无法在端口 80 上运行 [英] Node.js app can't run on port 80 even though there's no other process blocking the port

查看:48
本文介绍了即使没有其他进程阻塞该端口,Node.js 应用程序也无法在端口 80 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在安装了 Node.js 的 Amazon EC2 上运行 Debian 实例.如果我运行下面的代码:

I'm running an instance of Debian on Amazon EC2 with Node.js installed. If I run the code below:

http = require('http');

http.createServer(function (request, response){
  response.writeHead(200, {'Content-Type':'text/plain'});
  response.end('Hello World
');
}).listen(80);
console.log("Running server at port 80");

我得到下面的输出,它告诉我在端口 80 上侦听另一个进程:

I get the output below which tells me there's another process listening at port 80:

Running server at port 80

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EACCES
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1020:19)
    at listen (net.js:1061:10)
    at Server.listen (net.js:1127:5)
    at Object.<anonymous> (/home/admin/nodetests/nodetest.js:6:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

现在,当我检查是否有进程(以 root 身份,以防有任何东西被隐藏)监听端口 80 时,使用:

Now when I check to see if there's a process (as root in case anything is hidden) listening on port 80 using:

netstat -tupln

我得到下面的输出,它告诉我端口 80 没有监听:

I get the below output, which tells me theres nothing listening at port 80:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1667/sshd       
tcp6       0      0 :::22                   :::*                    LISTEN      1667/sshd

我应该注意到,如果这有所不同,debian 会将端口 80 作为入站规则打开.

I should note that the debian has port 80 open as an inbound rule if that makes a difference.

我的问题是:我做错了什么?为什么我无法识别监听 80 端口的进程?为什么它在 Debian 中被阻止?我应该采取哪些步骤才能使代码正确运行?

My question is: What am I doing wrong? How come I can't identify the process listening to port 80? Why is it blocked in Debian? What steps should I take to get the code running correctly?

推荐答案

错误代码 EACCES 表示您没有在该端口上运行应用程序的适当权限.在 Linux 系统上,任何低于 1024 的端口都需要 root 访问权限.

The error code EACCES means you don't have proper permissions to run applications on that port. On Linux systems, any port below 1024 requires root access.

这篇关于即使没有其他进程阻塞该端口,Node.js 应用程序也无法在端口 80 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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