修改Nginx用户和组

Posted l1-5551

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修改Nginx用户和组相关的知识,希望对你有一定的参考价值。

nginx 运行时进程需要有用户与组的支持,以实现对网站文件读取时进行访问控制。
Nginx 默认使用 nobody 用户账号与组账号,一般也要进行修改。

========================================================

1:编译安装时指定

[root@localhost conf]# useradd -M -s /sbin/nologin nginx

[root@localhost nginx-1.16.0]# tail -l /etc/passwd;tail -l /etc/group
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:988:982::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
roomc:x:1000:1000:roomc:/home/roomc:/bin/bash
named:x:25:25:Named:/var/named:/bin/false
nginx:x:1001:1001::/home/nginx:/sbin/nologin
avahi:x:70:
postdrop:x:90:
postfix:x:89:
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
tcpdump:x:72:
roomc:x:1000:
named:x:25:

[root@localhost ~]# tar xf nginx-1.16.0.tar.gz -C /usr/src
[root@localhost ~]# cd /usr/src/nginx-1.16.0/

[root@localhost nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module && make && make install

2:修改配置文件

[root@localhost nginx-1.16.0]# vim /usr/local/nginx/conf/nginx.conf

修改:

技术图片
user  nginx nginx;               
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events 
    use epoll;
    worker_connections  1024;
技术图片

[root@localhost nginx-1.16.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.16.0]# killall -s HUP nginx
nginx: no process found
[root@localhost nginx-1.16.0]# nginx
[root@localhost nginx-1.16.0]# killall -s HUP nginx
[root@localhost nginx-1.16.0]# ps -aux | grep nginx
root 22334 0.0 0.2 151560 5068 pts/1 T 13:33 0:00 vim /usr/local/nginx/conf/nginx.conf
root 25663 0.0 0.0 20692 1392 ? Ss 14:40 0:00 nginx: master process nginx
nginx 25667 0.0 0.0 23208 1488 ? S 14:40 0:00 nginx: worker process
nginx 25668 0.0 0.0 23208 1488 ? S 14:40 0:00 nginx: worker process
root 25678 0.0 0.0 112724 992 pts/1 S+ 14:41 0:00 grep --color=auto nginx

以上是关于修改Nginx用户和组的主要内容,如果未能解决你的问题,请参考以下文章

Nginx服务优化修改程序运行用户和组

为啥要修改nginx用户和组

Nginx优化

linux系统下怎么修改文件所属用户和组?

linux 查看mysql nginx用户和组

Linux用户和组管理未完成