解决nginx无法绑定80/443端口,

问题现象:普通用户启动nginx无法绑定80端口

image
image

# 错误如下
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
nginx: [emerg] bind() to 0.0.0.0:443 failed (13: Permission denied)
# 原因:普通用户只能使用大于1024以上的端口

处理方法

setcap 'cap_net_bind_service=+ep' /data/nginx/sbin/nginx

image

添加其他权限

参数 功能说明
CAP_NET_BIND_SERVICE 绑定到低于 1024 的端口(如 HTTP 80 端口)
CAP_SYS_ADMIN 执行系统管理操作(如挂载文件系统)
常用标志位 +ep:将能力添加到有效(effective)和 permitted 集合
+ei:仅添加到有效集合(不继承)
-r:移除文件的所有能力
posted @ 2024-11-07 17:48  91key  阅读(814)  评论(0)    收藏  举报