Maaz Zindani

Loading the index…

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

nginx fails with 99: Cannot assign requested address

Error(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.

  • Applies to nginx 1.26, Linux kernel 6, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 address
  2. 2Match what you see, then jump to its fix

    1. 1A bind() failure with error 99 when nginx starts or reloadsnginx binds to an IP address this machine does not haveFix
    2. 2connect() ... failed (99: Cannot assign requested address) while connecting to upstream, only under loadproxy_bind forces one source address, and its ports run outFix
    3. 3connect() ... 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

What does the error look like?

  • (99: Cannot assign requested address)
  • failed (99: Cannot assign requested address) while connecting to upstream
  • bind() 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=1

3Verify

Test the config and reload.

sudo nginx -t && sudo systemctl reload nginx

Confirmed by docs.kernel.org

Did this fix it?

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_range

2Fix

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 nginx

Confirmed by nginx.org

Did this fix it?

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_range

2Fix

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 -l

Confirmed by nginx.org

Did this fix it?

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

Next step

Want this handled for good?

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