為什么要更改 Nginx 服務的默認用戶:就像更改 ssh 的默認 22 端口一樣,增加安全性,Nginx 服務的默認用戶是 nobody ,我們更改為 nginx
1、添加 nginx 用戶
useradd nginx -s /sbin/nologin -M
2、更改 Nginx 配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
user nginx nginx; # 指定Nginx服務的用戶和用戶組
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server_tokens off;
server {
listen 80;
server_name www.abc.com;
location / {
root html/www;
index index.html index.htm;
}
}
}
3、重新加載 Nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t [root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
4、驗證是否生效
[root@localhost ~]# ps aux | grep nginx root 8901 0.0 0.1 45036 1784 ? Ss 13:54 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 8909 0.0 0.1 45460 1828 ? S 13:59 0:00 nginx: worker process # Nginx進程的所屬用戶為nginx

