【问题标题】:Run node js on ports 80 without running as root在端口 80 上运行节点 js,而不以 root 身份运行
【发布时间】:2018-11-20 19:13:05
【问题描述】:

我想在端口 80 上运行我的 node.js 应用程序而不以 root 身份运行它

$> which node
/usr/bin/node

我曾尝试使用 setcap,但它不起作用:

$> sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/node
Failed to set capabilities on file `/usr/bin/node' (Operation not 
permitted)
The value of the capability argument is not permitted for a file. Or 
the file is not a regular (non-symlink) file

我做错了什么?

【问题讨论】:

标签: node.js port port80


【解决方案1】:

最后,我使用了端口重定向,不是用 iptables 而是用 ufw

https://serverfault.com/questions/238563/can-i-use-ufw-to-setup-a-port-forward

【讨论】:

    【解决方案2】:

    低于 1000 的端口需要 sudo 权限。您可以使用以下命令允许它在不使用 sudo 的情况下绑定到端口 80:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-29
      • 2013-12-19
      相关资源
      最近更新 更多