nginx will not start: getpwnam failed for the user in nginx.conf
nginx: [emerg] getpwnam("www") failed in /etc/nginx/nginx.confShort 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.
Fix it fast
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/passwd2Match what you see, then jump to its fix
- 1
getpwnam("www") failed, and the grep for that name prints nothingThe user directive names an account this system does not haveFix - 2
Other files or deploy scripts depend on the name in the directiveYou need that exact account, so create itFix - 3
You changed the user line, but the same error comes backA different configuration file than the one you edited is loadedFix
- 1
What does the error look like?
nginx: [emerg] getpwnam("www") failed in /etc/nginx/nginx.confnginx: 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/passwd2Fix
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 nginxConfirmed by nginx.org
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/passwd2Fix
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 www3Verify
The account exists and nginx passes its test.
id www
sudo nginx -tConfirmed by man7.org
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 -t3Verify
The test reports that the syntax is ok.
sudo nginx -tConfirmed by nginx.org
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
Servers
A Let's Encrypt certificate did not renew with Certbot
Type: connection ... Timeout during connect (likely firewall problem)
Run sudo certbot renew --dry-run and read the Type and Detail lines.
6 causes, each with a fixServers
curl cannot connect to port 80 or 443 on a server running nginx
CURLE_COULDNT_CONNECT (7): Failed to connect() to host or proxy
Exit code 7 means the TCP connection itself failed, before any HTTP happened.
3 causes, each with a fixServers
Django returns a 500 behind Gunicorn and the traceback is nowhere
The traceback shows locally with runserver but not under Gunicorn
With DEBUG set to False, Django's default logging does not print errors to the console.
2 causes, each with a fixServers
Your website on a Google Compute Engine VM times out on port 80
The site works with curl on the VM but not from outside
A timeout, as opposed to a refusal, usually means a firewall dropped the packets.
3 causes, each with a fixServers
Gunicorn rejects a request with "Error parsing headers: limit request headers fields size"
Error parsing headers: 'limit request headers fields'
Gunicorn caps the size of one header field at 8190 bytes and the number of headers at 100 by default.
2 causes, each with a fixServers
HAProxy answers 503 "No server is available to handle this request"
No server is available to handle this request.
HAProxy sends 503 when it has no server to give a request to.
4 causes, each with a fix