错误:听EACCES 0.0.0.0:443

时间:2018-05-01 06:23:28

标签: node.js express

我正在尝试在我的MacOS上运行NodeJS的Web项目。

npm install之后,npm start会返回错误

events.js:183
  throw er; // Unhandled 'error' event
  ^

Error: listen EACCES 0.0.0.0:443
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at Server.setupListenHandle [as _listen2] (net.js:1334:19)
    at listenInCluster (net.js:1392:12)
    at Server.listen (net.js:1476:7)
    at Object.<anonymous> (/Users/softtimur/Startup/PRODSERVER/tmp/WeCard/models/www:36:8)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

我的Mac上没有其他网站正在运行。

有谁知道什么是错的?我是否需要在Mac上配置某些内容?

修改1:

sudo npm start返回

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::443
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at Server.setupListenHandle [as _listen2] (net.js:1351:14)
    at listenInCluster (net.js:1392:12)
    at Server.listen (net.js:1476:7)
    at Object.<anonymous> (/Users/softtimur/Startup/PRODSERVER/tmp/WeCard/models/www:36:8)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

4 个答案:

答案 0 :(得分:13)

要监听特权端口,您需要root权限才能启动服务器;这适用于端口&lt; 1024.您可以使用nginx作为在443上运行的反向代理服务器,并作为非特权用户在非特权端口上运行您的Node JS服务器。

有关在生产环境中使用nginx设置Node JS应用程序的更多信息,请点击以下链接: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-centos-7

答案 1 :(得分:4)

在类似UNIX的系统中,非root用户无法绑定到低于1024的端口。

当代理端口80上的地址时,这很麻烦。通常,您最终会欺骗必须绑定到此类端口的所有应用程序。

但是,从2.6.24内核开始,您可以使用setcap命令来设置程序的特定功能。

要使所有节点程序能够绑定到小于1024的任何端口,请发出以下命令:

sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node

注意:如果您不知道node的位置,请遵循以下命令。

sudo setcap 'cap_net_bind_service=+ep' `which node`

答案 2 :(得分:1)

我认为您可能希望为您的应用程序提供HTTPS,如果是这种情况,那么通常使用nodejs我们不会直接从我们的节点应用程序使用HTTPS。相反,我们使用nginx(Web服务器)充当&#34;反向代理&#34;。这意味着nginx位于我们的应用程序前面,它为我们侦听端口443,然后将请求发送到我们想要的应用程序。

使用nginx,您可以侦听端口443,然后根据主机名等重定向到多个不同的服务。例如,我可能在一台服务器上运行3个Web服务,使用nginx我可以在端口443上侦听任何HTTP连接。如果HTTP请求发送到主机myblog.com,它可以将其发送到侦听端口8081的节点服务。如果请求上的主机名是myresume.com,它可能会转到端口8082和myprivatethings.com上的服务器可以去8083号港口。

使用类似nginx的东西(存在许多替代方案),您可以在一台服务器上使用SSL / TLS(https)管理多个服务。

答案 3 :(得分:0)

最重要的是,不要以root身份运行。这就是要求'它'。 “它”非常糟糕。去看看the movie。然后,不要以root用户身份运行节点Web项目。

相反,请使用PM2authbind执行此操作:

// %user% is whatever user is running your code
sudo touch /etc/authbind/byport/443
sudo chown %user% /etc/authbind/byport/443
sudo chmod 755 /etc/authbind/byport/443

接下来,将此别名添加到您的~/.bashrc~/.bash_profile

alias pm2='authbind --deep pm2'

然后,用pm2尝试:

pm2 start app.js
相关问题