nginx进程属主问题讨论

   文章作者:luxianghao

   文章来源:http://www.cnblogs.com/luxianghao/p/6107096.html 转载请注明,谢谢合作。

   免责声明:文章内容仅代表个人观点,如有不当,欢迎指正。

   --- 

近来由于工作需求,和nginx接触较多,现把关于nginx进程属主的问题总结如下:

规则
nginx启动进程可以在conf里指定user(user  work;)但是这个只有在用root启动的情况有意义,
如果是用其他用户启动的nginx master是没有意义的 nginx会忽略这个配置,如下nginx warning所述
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /home/work/app/nginx/conf/nginx.conf:1
 
结论
1,在非root账户下启动时,nignx的master和worker进程的owner都将是这个账户,
2,在root账户下启动时 nignx的master进程是的owner是root,worker的owner在conf已配置用户的情况下,owner是配置的用户,否则将是nobody,而且也可能导致nginx的一些文件的owner也是nobody
 
# ps -ef | grep nginx
work     26620 21666  0 19:18 pts/5    00:00:00 vim conf/nginx.conf
root     26901     1  0 19:19 ?        00:00:00 nginx: master process ./sbin/nginx
nobody   26902 26901  0 19:19 ?        00:00:00 nginx: worker process
nobody   26903 26901  0 19:19 ?        00:00:00 nginx: worker process
nobody   26904 26901  0 19:19 ?        00:00:00 nginx: worker process
nobody   26905 26901  0 19:19 ?        00:00:00 nginx: worker process
nobody   26906 26901  0 19:19 ?        00:00:00 nginx: worker process
nobody   26910 26901  0 19:19 ?        00:00:00 nginx: cache manager process
nobody   26911 26901  0 19:19 ?        00:00:00 nginx: cache loader process
root     26918 24078  0 19:19 pts/11   00:00:00 grep nginx
 
# ll
total 72
drwxrwxr-x 7 work   work 4096 Jul 15 11:55 _book
drwxr-xr-x 2 nobody work 4096 Jul 15 11:55 cache
drwx------ 2 nobody work 4096 Jul 15 11:55 client_body_temp
drwxrwxr-x 2 work   work 4096 Nov 27 19:18 conf
drwx------ 2 nobody work 4096 Jul 15 11:55 fastcgi_temp
drwxrwxr-x 2 work   work 4096 Jul 15 11:55 html
drwx------ 2 nobody work 4096 Jul 15 11:55 uwsgi_temp
原文地址:https://www.cnblogs.com/luxianghao/p/6107096.html