nginx优化-使用普通用户启动nginx(监牢模式)
2018-10-15 19:28
901 查看
使用普通用户启动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   b60 ; /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
浏览器访问测试
相关文章推荐
- nginx安全优化之用普通用户运行master
- linux下普通用户如何使用80端口启动程序
- linux权限--普通用户使用livecd模式
- 普通用户启动nginx
- 使用普通用户启动tomcat
- linux下普通用户如何使用80端口启动程序
- nginx优化2<nginx 跑在普通用户下>
- CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动
- Hadoop的完全分布模式配置——以普通用户'hadoop'启动
- 用普通用户运行nginx(安全优化)
- Linux下配置Tomcat使用普通用户启动Daemon进程
- Linux 普通用户启动nginx
- nginx赋能普通用户可以使用1024以下端口
- Linux下配置Tomcat使用普通用户启动Daemon进程
- linux下普通用户如何使用80端口启动程序
- 使用sudo来赋予普通用户root的权限 推荐
- linux内核初始化及启动之用户模式开始
- 遇到当试图还原 master 数据库时,必须以单用户模式使用 RESTORE DATABASE.的解决办法
- 极品五笔管理员能用,普通用户无法使用
- 使用观察者模式在 Silverlight 中切换用户控件