3

I am running a chrooted nginx server on CentOS 7. When I try to start nginx, I receive this error: getpwnam("nginx") failed in /etc/nginx/nginx.conf:5. I have already copied the required libraries, directories (/etc, /var, /proc, /usr, /lib, /dev), etc. I am starting the service as root.

My 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

User/group is present:

[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:

Also, my custom nginx.service file:

[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 version:

[root@centos user]# yum info nginx
Installed Packages
Name        : nginx
Arch        : x86_64
Epoch       : 1
Version     : 1.10.2
Release     : 1.el7 
  • you need a minimal copy of /etc/passwd in the chroot, at least with the nginx user – Rui F Ribeiro Aug 16 '17 at 22:14
  • @RuiFRibeiro As I stated above, I have already copied all of the relevant directories and files: [root@centos /]# cat /var/www/chroot/etc/passwd | grep nginx -> nginx:x:993:988:Nginx web server:/var/lib/nginx:/bin/bash. – N.M.D Aug 16 '17 at 23:20
  • 1
    To be fair, you demonstrated cat /etc/passwd , not the chroot path. – Jeff Schaller Aug 16 '17 at 23:53
  • 1
    @JeffSchaller fair point. – N.M.D Aug 17 '17 at 4:10
  • 3
    getpwnam(3) and friends use nsswitch to get the actual data. nsswitch supports different data sources implemented as modules (libraries loaded through dlopen(3)). You need to have both nsswitch.conf and the selected modules available in your chroot environment: Check the passwd field in nsswitch.conf and make sure you have the corresponding module in your chroot (e.g. /lib/libnss_files-X.XX.so). – Andreas Wiese Aug 17 '17 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.