Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

nginx will not start: getpwnam failed for the user in nginx.conf

Errornginx: [emerg] getpwnam("www") failed in /etc/nginx/nginx.conf

Short answer

The user directive in nginx.conf names an account that does not exist on this server, so nginx cannot start its workers. Look up which account exists, then set the directive to it, or create a system user with that name. Check that the file you edited is the one nginx really loads.

  • Applies to nginx 1.26, Ubuntu 24.04, Debian 12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the user line nginx is using and check whether that account is in the password file.

    grep -n "^user" /etc/nginx/nginx.conf
    grep -E "^(www|www-data|nginx|nobody):" /etc/passwd
  2. 2Match what you see, then jump to its fix

    1. 1getpwnam("www") failed, and the grep for that name prints nothingThe user directive names an account this system does not haveFix
    2. 2Other files or deploy scripts depend on the name in the directiveYou need that exact account, so create itFix
    3. 3You changed the user line, but the same error comes backA different configuration file than the one you edited is loadedFix

What does the error look like?

  • nginx: [emerg] getpwnam("www") failed in /etc/nginx/nginx.conf
  • nginx: configuration file /etc/nginx/nginx.conf test failed

Cause 1 of 3

The user directive names an account this system does not have

1Check

The user directive sets the account for worker processes. Its default is nobody. A name copied from another system, such as www, fails when no such account exists.

grep -E "^(www|www-data|nginx):" /etc/passwd

2Fix

Point the directive at an account that exists. If you give only a user, the group with the same name is used.

# /etc/nginx/nginx.conf
user www-data;

3Verify

Test the configuration and start nginx.

sudo nginx -t
sudo systemctl start nginx

Confirmed by nginx.org

Did this fix it?

Cause 2 of 3

You need that exact account, so create it

1Check

Confirm that no account of that name exists before adding one.

grep "^www:" /etc/passwd

2Fix

Create a system account. useradd -r makes a system account and does not create a home directory; by default it creates a group with the same name, which is what nginx uses when only the user is set.

sudo useradd --system www

3Verify

The account exists and nginx passes its test.

id www
sudo nginx -t

Confirmed by man7.org

Did this fix it?

Cause 3 of 3

A different configuration file than the one you edited is loaded

1Check

nginx -T tests the configuration and prints every file it loads, with the user directive that is really in effect.

sudo nginx -T 2>/dev/null | grep -n "^user\|configuration file"

2Fix

Edit the file the dump shows. If you start nginx with -c, pass the same file to the test.

sudo nginx -c /etc/nginx/nginx.conf -t

3Verify

The test reports that the syntax is ok.

sudo nginx -t

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • Do not copy nginx.conf between distributions without checking the user line.
  • Run nginx -t after every config change and before every restart.
  • Create service accounts in your provisioning scripts, not by hand.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.