温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

nginx优化2<nginx 跑在普通用户下>

发布时间:2020-07-28 11:47:33 来源:网络 阅读:441 作者:674591788 栏目:建站服务器

 优化2:

随笔记载,有问题欢迎指正。

修改nginx默认用户和用户组:

useradd nginx -s /sbin/nologin -M ###不允许登录

groupadd nginx

修改用户和用户组都是针对nginx的worker进程的,但是master经常还是root的

一个是在编译的时候指定用户和组:

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-pcre=/opt/soft/pcre-8.12 

一个是修改nginx.conf

全局配置项:

user  www www;


重点:

让nginx用户跑在普通用户下:

useradd zuma

su - zuma

如果新建的用户没有环境变量:

解决:

su - zuma

cp /etc/skel/.bash* .

exit

su - zuma


如果还是没有环境变量,需要检查一下cat  /etc/default/useradd 里面有没有其他的配置

# useradd defaults file

GROUP=100

HOME=/home

INACTIVE=-1

EXPIRE=

SHELL=/bin/bash

SKEL=/etc/skel

CREATE_MAIL_SPOOL=yes


删除用户

userdel -r zuma 


su - zuma 进入到zuma的用户目录:

拷贝conf文件夹 web目录文件夹 到/home/zuma目录下面:

cp -ap /usr/local/nginx/conf .

cp -ap /usr/local/nginx/html .

ln -s /usr/local/nginx/logs logs


切换到root用户:

chmod -R 755 /usr/local/nginx/logs

chown -R .zuma /usr/local/nginx/logs

su - zuma

启动nginx即可:

/usr/local/nginx/sbin/nginx -c /home/zuma/conf/nginx.conf

可以通过ps -ef|grep nginx 查看。

root     16127     1  0 11:48 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

www      16128 16127  0 11:48 ?        00:00:01 nginx: worker process      

www      16129 16127  0 11:48 ?        00:00:00 nginx: worker process      

www      16130 16127  0 11:48 ?        00:00:01 nginx: worker process      

www      16131 16127  0 11:48 ?        00:00:01 nginx: worker process      

zuma     20162     1  0 14:25 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /home/zuma/conf/nginx.conf

zuma     20163 20162 14 14:25 ?        00:00:00 nginx: worker process                                    

zuma     20164 20162 27 14:25 ?        00:00:00 nginx: worker process                                    

zuma     20166 16484  1 14:26 pts/1    00:00:00 grep nginx


向AI问一下细节
推荐阅读:
  1. Nginx优化
  2. Nginx初步优化

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI