gpt4 book ai didi

linux - 为什么在端口 80 上运行 node.js 可能不安全?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:22:21 25 4
gpt4 key购买 nike

我知道 nodejs 可以通过以下方式在端口 80 上运行:

  • 使用 apache/nginx 设置代理
  • 使用 iptables 规则设置端口重定向
  • 在应用内的端口 80 上进行快速监听

第一个选项不是最简单的,它需要比我需要更多的依赖项。第二个可以工作,但在我的 OpenVZ VPS 上它不会(而且我无法编译自定义 linux 内核)。

我也需要处理一些子域,在阅读此 stackoverflow answer 之后,我尝试了第三种解决方案。它运行良好且非常容易执行。

我想知道直接在80端口运行nodejs会不会有一些安全问题?我该如何修复/找到这些?

我想使用 pm2 来处理进程,它可能会运行 not as root (Goodbye node-forever hello pm2)。

最佳答案

The first option isn't the easiest and require more dependencies then I need

请查看why should one use a http server in front of a framework web server出于许多正当理由,实际上您应该这样做

setting up a port redirection with an iptables rule

这可能比直接让您的 Node 进程在端口 80 上监听要好,尽管我还没有在生产中看到这种类型的配置。

making express listen on port 80 within the app

这在功能上是一个糟糕的选择,因为您没有获得上面链接答案中概述的好处,但是,从严格的安全角度来看,要记住的关键是您不能以 root 身份运行 Node 进程,这将是一个可怕的安全问题。您必须是 root 才能绑定(bind)到端口 80,因为这是 unix 的规则,但您可以而且必须在绑定(bind)到该端口后立即更改为权限较低的用户。

关于linux - 为什么在端口 80 上运行 node.js 可能不安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19409749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com