2017-02-19 337 views
2

我使用Ansible安装了Nginx。为了在Centos7上安装,我使用了yum软件包,所以默认情况下运行的是root用户。我希望它在Centos框中以不同的用户身份启动并运行(例如 - nginx用户)。当我尝试用不同的用户运行它时,出现以下错误:以非root用户身份运行Nginx

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

我知道不建议以root身份运行。那么我该如何解决这个问题,并以非root用户身份运行nginx。由于

+0

堆栈溢出nginx的运行是用于编程和发展问题的站点。这个问题似乎与题目无关,因为它不涉及编程或开发。请参阅帮助中心的[我可以询问哪些主题](http://stackoverflow.com/help/on-topic)。也许[超级用户](http://superuser.com/)或[Unix&Linux堆栈交换](http://unix.stackexchange.com/)会是一个更好的地方。另请参阅[我在哪里发布有关Dev Ops的问题?](http://meta.stackexchange.com/q/134306) – jww

+0

也许[允许非root进程绑定到端口80和443?](http:// superuser.com/q/710253/173513)和[绑定到没有root访问权的小于1024的端口](https://serverfault.com/questions/268099/bind-to-ports-less-than-1024-without-root - 访问)将有所帮助。另请参阅[是否有非root进程绑定到Linux上“特权”端口(<1024)的方式?](http://stackoverflow.com/q/413807/608639)。 – jww

回答

5

添加/更改您的/etc/nginx/nginx.conf如下:

user nginx; 

你应该在根目录目录创建用户和授予权限递归。

这种方式只有主进程运行为root因为:只有根进程可以侦听1024以下的端口。网络服务器通常运行在端口80和/或443上。这意味着它需要以root身份启动。

要运行的主进程作为非根用户:

更改以下的所有权:

  • 的error_log
  • 的access_log
  • PID
  • client_body_temp_path
  • fastcgi_temp_path
  • proxy_temp_path
  • scgi_temp_path
  • uwsgi_temp_path

更改听指令到端口上方1024,登录为所需的用户,并通过nginx -c /path/to/nginx.conf

+0

嗨Farhad。这是在conf文件中默认设置给这个用户的。我试过了 - 对于nginx并启动它,仍然是根。 – Sarith

+0

'ps aux | grep nginx'显示root? –

+0

是的。见下文。 root 5830 0.0 0.1 122232 2216? Ss 17:07 0:00 nginx:主进程/ usr/sbin/nginx nginx 5831 0.0 0.1 122664 3292? S 17:07 0:00 nginx:工作进程 nginx 5832 0.0 0.1 122664 3088?S 17:07 0:00 nginx:工作进程 – Sarith

相关问题