码迷,mamicode.com
首页 > 其他好文 > 详细

更改 Nginx 服务的默认用户

时间:2018-07-15 11:12:14      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:timeout   验证   file   ali   技术分享   RoCE   event   复制   col   

为什么要更改 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

 

更改 Nginx 服务的默认用户

标签:timeout   验证   file   ali   技术分享   RoCE   event   复制   col   

原文地址:https://www.cnblogs.com/shamo89/p/9311811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!