- 主進(jìn)程是root用戶
- 沒有做任何配置:nobody
- 編譯時(shí)配置:./configure 指定的 --user=USER
- nginx.conf配置:user user [group];(只有以root用戶啟動(dòng)時(shí)才生效)
filename: auto/unix
# Copyright (C) Igor Sysoev
# Copyright (C) Nginx, Inc.
NGX_USER=${NGX_USER:-nobody}
filename: auto/options
......
--user=*) NGX_USER="$value" ;;
--group=*) NGX_GROUP="$value" ;;
......
- 主進(jìn)程是非root用戶
- 繼承主進(jìn)程的用戶
filename: src/os/unix/ngx_process.c
if (geteuid() == 0) {
if (setgid(ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setgid(%d) failed", ccf->group);
/* fatal */
exit(2);
}
...
if (setuid(ccf->user) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setuid(%d) failed", ccf->user);
/* fatal */
exit(2);
}
...
}