我在 CentOS 7 上运行 chroot nginx 服务器。当我尝试启动 nginx 时,收到此错误:getpwnam("nginx") failed in /etc/nginx/nginx.conf:5
。我已经复制了所需的库、目录 ( /etc, /var, /proc, /usr, /lib, /dev
) 等。我以 root 身份启动该服务。
我的 nginx.conf:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
[root@centos user]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
用户/组存在:
[root@centos user]# cat /var/www/chroot/etc/passwd | grep nginx
nginx:x:993:988:Nginx web server:/var/lib/nginx:/bin/bash
[root@centos user]# cat /var/www/chroot/etc/group | grep nginx
nginx:x:988:
另外,我的自定义 nginx.service 文件:
[Unit]
Description=A high performance web server and a reverse proxy server in a
chroot jail
After=syslog.target network.target
[Service]
Type=forking
RootDirectory=/var/www/chroot
PIDFile=/var/www/chroot/run/nginx.pid
ExecStartPre=/usr/sbin/chroot /var/www/chroot /usr/sbin/nginx -t -q -g 'pid
/run/nginx.pid; daemon on; master_process on;'
ExecStart=/usr/sbin/chroot /var/www/chroot /usr/sbin/nginx -g 'pid
/run/nginx.pid; daemon on; master_process on;'
ExecReload=/usr/sbin/chroot /var/www/chroot /usr/sbin/nginx -g 'pid
/run/nginx.pid; daemon on; master_process on;' -s reload
ExecStop=/usr/sbin/chroot /var/www/chroot /usr/sbin/nginx -g 'pid
/run/nginx.pid;' -s quit
RootDirectoryStartOnly=yes
[Install]
WantedBy=multi-user.target
nginx 版本:
[root@centos user]# yum info nginx
Installed Packages
Name : nginx
Arch : x86_64
Epoch : 1
Version : 1.10.2
Release : 1.el7