nginx fails with 99: Cannot assign requested address
(99: Cannot assign requested address)Short answer
Error 99 means the kernel refused to use a local address or port that nginx asked for. Either nginx names an IP the machine does not own (listen or proxy_bind), or under heavy traffic it ran out of local ports for outgoing upstream connections. The error log line says which one.
Fix it fast
1Find out which cause you have
Read the full error line. 'bind()' at start-up or reload points to an address in the config. 'connect() ... while connecting to upstream' under traffic points to local ports.
sudo tail -n 30 /var/log/nginx/error.log ip -brief address2Match what you see, then jump to its fix
- 1
A bind() failure with error 99 when nginx starts or reloadsnginx binds to an IP address this machine does not haveFix - 2
connect() ... failed (99: Cannot assign requested address) while connecting to upstream, only under loadproxy_bind forces one source address, and its ports run outFix - 3
connect() ... failed (99: Cannot assign requested address) while connecting to upstream, and ss shows thousands of TIME-WAIT socketsEvery request opens a new upstream connection and local ports run outFix
- 1
What does the error look like?
(99: Cannot assign requested address)failed (99: Cannot assign requested address) while connecting to upstreambind() failed (99: Cannot assign requested address)
Cause 1 of 3
nginx binds to an IP address this machine does not have
1Check
Compare the address in listen or proxy_bind with the addresses the server really owns. Cloud servers often have a public IP that is NAT-mapped and never appears on the interface; a floating IP may exist only on another node.
ip -brief address
grep -R -n -E "listen|proxy_bind" /etc/nginx/2Fix
Listen on an address that is on the machine (or on all addresses with just a port). If the address is a floating IP that only appears after failover, allow binding to non-local addresses with the kernel setting ip_nonlocal_bind.
# nginx
listen 80;
# only when you really need a not-yet-local IP
sudo sysctl -w net.ipv4.ip_nonlocal_bind=13Verify
Test the config and reload.
sudo nginx -t && sudo systemctl reload nginxConfirmed by docs.kernel.org
Cause 2 of 3
proxy_bind forces one source address, and its ports run out
1Check
proxy_bind makes upstream connections start from one local IP. Each connection from one source address to one upstream address and port needs its own local port from a limited range.
grep -R -n "proxy_bind" /etc/nginx/
cat /proc/sys/net/ipv4/ip_local_port_range2Fix
Remove proxy_bind if you do not need it, or set it to off so the system picks the address and port.
location / {
proxy_pass http://127.0.0.1:3000;
proxy_bind off;
}3Verify
Reload and repeat the load that failed.
sudo nginx -t && sudo systemctl reload nginxConfirmed by nginx.org
Cause 3 of 3
Every request opens a new upstream connection and local ports run out
1Check
Each new connection to the same upstream needs a local port, and the default range is 32768-60999. Without upstream keepalive, nginx opens a new connection per request, and closed ones wait in TIME-WAIT.
ss -tan state time-wait | wc -l
cat /proc/sys/net/ipv4/ip_local_port_range2Fix
Reuse upstream connections with keepalive in an upstream block, with HTTP/1.1 and a cleared Connection header.
upstream app {
server 127.0.0.1:3000;
keepalive 32;
}
server {
location / {
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}3Verify
Reload, repeat the load test and count TIME-WAIT sockets again.
sudo nginx -t && sudo systemctl reload nginx
ss -tan state time-wait | wc -lConfirmed by nginx.org
How do I stop it coming back?
- Use keepalive for every busy upstream.
- Listen on a port only, unless you must pin an address, and keep a floating-IP setup documented.
- Count TIME-WAIT sockets during load tests to see port pressure early.
- Widen net.ipv4.ip_local_port_range only after keepalive is in place, and test the change.
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