记一次使用普通用户同时启动nginx <1024端口和>1024端口权限问题
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
nginx 默认安装目录:/usr/local/nginx
chown -R nginx:nginx nginx
chmod u+s nginx
正常使用 nginx 用户启动会有错误sudo -unginx nginx
Starting nginx... nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:1
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
因为项目里面有很多域名,80 端口和大于 1024 的端口都存在,nginx 是不允许用普通用户启动80 端口
我们只需要进入到/usr/local/nginx/sbin
执行
setcap cap_net_bind_service=+eip nginx
设置bind 权限
然后再去查看权限:getcap nginx
输出:nginx = cap_net_bind_service+eip
再去检测:sudo -uhnnx nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
最后我们执行:service nginx start
|| sudo -uhnnx nginx
无论如何,解决问题就行
本作品采用《CC 协议》,转载必须注明作者和本文链接
总监牛逼