【问题标题】:How to bind 80 non-root如何绑定80个非root
【发布时间】:2016-02-06 19:50:45
【问题描述】:

在没有 root 权限的情况下,是否可以将 Mac OS 上的程序绑定到 :80,例如在 Linux 上让用户 www 能够这样做。

有什么想法吗?谢谢

【问题讨论】:

  • 不,在 Linux 上也做不到。绑定到端口 bind() 并切换其有效 UID,例如到“www”,稍后。有关如何在您的进程等待端口 > 1024 时调整端口 80 的想法,请参阅this question in Ask Different
  • 这不是真的,在 linux 上你可以用sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node 设置 CAP_NET_BIND_SERVICE。不幸的是 OS X 无法识别这个选项。

标签: macos http nginx apache2


【解决方案1】:

您是否担心不希望 nginx 以 root 身份运行或者您没有 root 访问权限?

Nginx 有一个 user 配置选项,它会在绑定到端口后删除 root。

如果您没有 root 访问权限,我知道在 OS X 上的最佳解决方案是使用 pf 将 ip 重定向设置到非特权端口,但是您仍然需要让具有 root 访问权限的人访问这样做。

pf 的配置存储在 /etc/pf.conf 中 - 我相信您可以简单地在该文件中添加规则并重新加载 pf 以使其生效。

rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 8081

然后用sudo pfctl -F all -ef /etc/pf.conf重新加载pf并配置nginx监听重定向到的端口。

【讨论】:

  • 是的,我担心以 root 身份运行 nginx,并且我确实具有 root 访问权限,第一个解决方案对我有用,我将用户设置为 _www ,但主进程仍然以 root 身份运行,但我猜那个使用 nginx 时无法停止。 PS辅助:_www 1614 0,0 0,0 2464100 1008 ?? S 10:48 0:00.00 nginx:工作进程根 1613 0,0 0,0 2463880 2516 ?? ss 10:48 0:00.01 nginx:主进程/usr/local/opt/nginx/bin/nginx -g daemon off;
猜你喜欢
  • 2011-08-14
  • 1970-01-01
  • 2013-05-26
  • 1970-01-01
  • 2014-02-24
  • 2015-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多