使用普通用户启动nginx(监牢模式)
nginx运行时,主进程一般是由root管理的
[root@web01 ~]# ps aux|grep nginx root 1340 0.0 0.8 572132 1488 ? Ss 02:41 0:00 nginx: master process /application/nginx/sbin/nginx www 1341 0.0 5.9 580624 10160 ? S 02:41 0:00 nginx: worker process www 1342 0.0 5.9 580624 10180 ? S 02:41 0:00 nginx: worker process www 1343 0.0 1.1 572132 1980 ? S 02:41 0:00 nginx: cache manager process www 1344 0.0 1.0 572132 1856 ? S 02:41 0:00 nginx: cache loader process root 1352 0.0 0.4 103332 844 pts/0 S+ 02:41 0:00 grep --color=auto nginx
部署环境
[root@web01 tools]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@web01 scripts]# uname -r 2.6.32-696.el6.x86_64 [root@web01 tools]# uname -m x86_64 [root@web01 tools]# uname -a Linux moban 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux [root@web01 ~]# getenforce Disabled [root@web01 ~]# /etc/init.d/iptables status iptables: Firewall is not running. [root@web01 ~]# ls /application/ nginx nginx-1.14 php php-5.5.32
在普通用户家目录中 创建nginx程序目录
useradd cjh su - cjh mkdir -p nginx mkdir -p nginx/{conf,html,logs}
添加生成配置文件和数据文件信息
cp /application/nginx/conf/nginx.conf ~/nginx/conf/ cp /application/nginx/conf/mime.types ~/nginx/conf/ ll ~/nginx/conf/
编写nginx配置文件
强调说明:对于普通用户启动的一些网络服务,不能使用知名端口号(1-1024)
vim ~/nginx/conf/nginx.conf
worker_processes 2; worker_cpu_affinity 0101 1010; worker_rlimit_nofile 65535; error_log /home/cjh/nginx/logs/error.log; #user cjh cjh; #普通用户不能使用此参数配置 pid /home/cjh/nginx/logs/nginx.pid; events { use epoll; worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /home/cjh/nginx/logs/access.log main; server { listen 8080; server_name www.123.org; root /home/cjh/nginx/html; index index.html index.htm; } }
nginx -p 指定程序路径-只有在检查语法时可以使用
/application/nginx/sbin/nginx -t -p ~/nginx/
[cjh@web01 ~]$ /application/nginx/sbin/nginx -t -p ~/nginx/ nginx: the configuration file /home/cjh/nginx/conf/nginx.conf syntax is ok nginx: configuration file /home/cjh/nginx/conf/nginx.conf test is successful
nginx -c 指定配置文件路径-可以指定配置文件进行(检查语法 可以启动nginx)
监牢模式 检查配置文件
/application/nginx/sbin/nginx -t -p ~/nginx/
[cjh@web01 ~]$ /application/nginx/sbin/nginx -t -p ~/nginx/ nginx: the configuration file /home/cjh/nginx/conf/nginx.conf syntax is ok nginx: configuration file /home/cjh/nginx/conf/nginx.conf test is successful
/application/nginx/sbin/nginx -t -c ~/nginx/conf/nginx.conf
[cjh@web01 ~]$ /application/nginx/sbin/nginx -t -c ~/nginx/conf/nginx.conf nginx: [alert] could not open error log file: open() "/application/nginx-1.14/logs/error.log" failed (13: Permission denied) 2018/10/14 03:05:46 [warn] 1690#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /home/cjh/nginx/conf/nginx.conf:5 #注意下面两行即可 nginx: the configuration file /home/cjh/nginx/conf/nginx.conf syntax is ok nginx: configuration file /home/cjh/nginx/conf/nginx.conf test is successful
监牢模式 启动nginx
/application/nginx/sbin/nginx -c ~/nginx/conf/nginx.conf
[cjh@web01 ~]$ /application/nginx/sbin/nginx -c ~/nginx/conf/nginx.conf nginx: [alert] could not open error log file: open() "/application/nginx-1.14/logs/error.log" failed (13: Permission denied) 2018/10/14 03:07:18 [warn] 1709#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /home/cjh/nginx/conf/nginx.conf:5
检查监牢模式的nginx
ps aux|grep nginx
[cjh@web01 ~]$ ps aux|grep nginx root 1340 0.0 0.9 572132 1624 ? Ss 02:41 0:00 nginx: master process /application/nginx/sbin/nginx www 1341 0.0 6.0 580624 10236 ? S 02:41 0:00 nginx: worker process www 1342 0.0 6.0 580624 10244 ? S 02:41 0:00 nginx: worker process www 1343 0.0 1.1 572132 1980 ? S 02:41 0:00 nginx: cache manager process cjh 1710 0.0 0.6 44744 1088 ? Ss 03:07 0:00 nginx: master process /application/nginx/sbin/nginx -c /home/cjh/nginx/conf/nginx.conf cjh 1711 0.0 0.9 45176 1540 ? S 03:07 0:00 nginx: worker process cjh 1712 0.0 0.8 45176 1532 ? S 03:07 0:00 nginx: worker process cjh 1714 0.0 0.4 103332 840 pts/0 S+ 03:07 0:00 grep --color=auto nginx
创建首页文件
echo "cjh mail 2395444211@qq.com" > ~/nginx/html/index.html
浏览器访问测试
转载于:https://blog.51cto.com/13673885/2300280