在实际生产环境中,有时我们需要普通用户管理nginx服务,也就是将nginx在普通用户下运行。采用这种方式的好处:
1)上线方便
上线的时候可以直接把 conf(配置文件目录)、html(数据文件目录) 目录直接干掉,后面推送过来,重启服务即可。
2)应用层隔离
3)环境标准化
4)可管理性
环境设置
一、首先要有编译好nginx
编译方法见:http://blog.csdn.net/m0_37886429/article/details/68941918
二、创建管理nginx服务的用户,并拷贝配置、数据、日志目录
[root@linux-node ~]# useradd test
[root@linux-node ~]# cd /home/test/
[root@linux-node test]# cp -a /usr/local/nginx/conf /home/test/ #拷贝主配置目录
[root@linux-node test]# cp -a /usr/local/nginx/html /home/test/ #拷贝数据目录
[root@linux-node test]# cp -a /usr/local/nginx/logs/ /home/test/ #拷贝日志目录
三、修改配置文件参数并启动
[root@linux-node test]# grep 'test' /home/test/conf/nginx.conf
user test test;
error_log /home/test/logs/error.log crit;
pid /home/test/logs/nginx.pid;
#扩展配置文件
[root@linux-node test]# grep 'test' /home/test/conf/vhost/test.conf
#server_name test.jiujijianghu.com;
root /home/test/html; #代码目录
access_log /home/test/logs/access.log;
#启动服务
[root@linux-node test]# /usr/local/nginx/sbin/nginx -c /home/test/conf/nginx.conf
备注:这样可以让不同用户负责不同的程序