记一次使用普通用户同时启动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

记一次使用普通用户同时启动nginx <1024端口和>1024端口权限问题

无论如何,解决问题就行

本作品采用《CC 协议》,转载必须注明作者和本文链接
每天一点小知识,到那都是大佬,哈哈
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!