Get the App
SLTechnology News&Howtos  ›  Servers  › 

Nginx optimized change user

Shulou Source: shulou.com Published: 2022-06-02 23:22:18 10月06日 Update

1.1 change the nginx default user

Change the default user of nginx. Generally, the default user is nobody after nginx is started.

[root@web01 conf] # grep'# user' nginx.conf.default

# user nobody

[root@web01 conf] #

In order to prevent * * guessing the user of this web service, we need to change it to a special name, such as nginx or CC with special points, but this user must exist in advance in the system and use nginx to make a special description.

1.1.1 nginx service creates new users

Create a new user action for nginx as follows

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

[root@web01 ~] # id nginx

Uid=1310 (nginx) gid=1310 (nginx) groups=1310 (nginx)

[root@web01 ~] #

1.1.2 configure the nginx service to use the newly created nginx user

There are two default users for changing nginx

The first is to change the profile parameters directly

[root@web01 conf] # grep'# user' nginx.conf.default

# user nginx

The second method is to specify the user and group commands to compile when compiling nginx software directly:

. / configure-user=nginx-group=nginx...

1.2 check the effect of changing the user

After reloading the configuration, check the corresponding user of the nginx service process, as follows

[root@web01 ~] # ps-ef | grep nginx

Root 1409 1 0 21:38? 00:00:00 nginx: master process / application/nginx/sbin/nginx

Nginx 1803 1409 0 23:58? 00:00:00 nginx: worker process

Root 1808 1786 0 23:59 pts/0 00:00:00 grep nginx

[root@web01 ~] # ps-ef | grep nginx | grep-v grep

The main process becomes root worker press, the user becomes nginx.

Tags: User service special configuration process creation check compile parameter name command effect file method system software special point Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi Linux Redmi Shulou Technology