{"record":{"id":"13d166e96917790b","repo":"nginx/nginx","slug":"ngx-log-crit-13d166","errorCode":"NGX_LOG_CRIT","errorMessage":"bind(%V) failed","messagePattern":"bind\\(%V\\) failed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/event/ngx_event_connect.c","lineNumber":165,"sourceCode":"#if (NGX_LINUX)\n\n        if (pc->type == SOCK_DGRAM && port != 0) {\n            int  reuse_addr = 1;\n\n            if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,\n                           (const void *) &reuse_addr, sizeof(int))\n                 == -1)\n            {\n                ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,\n                              \"setsockopt(SO_REUSEADDR) failed\");\n                goto failed;\n            }\n        }\n\n#endif\n\n        if (bind(s, pc->local->sockaddr, pc->local->socklen) == -1) {\n            ngx_log_error(NGX_LOG_CRIT, pc->log, ngx_socket_errno,\n                          \"bind(%V) failed\", &pc->local->name);\n\n            goto failed;\n        }\n    }\n\n    if (type == SOCK_STREAM) {\n        c->recv = ngx_recv;\n        c->send = ngx_send;\n        c->recv_chain = ngx_recv_chain;\n        c->send_chain = ngx_send_chain;\n\n        c->sendfile = 1;\n\n        if (pc->sockaddr->sa_family == AF_UNIX) {\n            c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;\n            c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED;\n","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/nginx/nginx/blob/3f6f7824d4e2eb1ac37dec76683d525ac0ff521c/src/event/ngx_event_connect.c#L147-L183","documentation":"bind() of the local address configured by proxy_bind (pc->local) failed before connecting upstream. Logged at CRIT and fatal for the attempt: socket closed, request fails for that peer. Typical errnos: EADDRNOTAVAIL (IP not assigned on any interface), EADDRINUSE (port already taken), EACCES (privileged port <1024 without CAP_NET_BIND_SERVICE).","triggerScenarios":"proxy_bind 10.0.0.5; where 10.0.0.5 is not present on the box; proxy_bind with a port another process owns; binding to 0.0.0.0:53 without root; transparent-proxy misconfiguration binding arbitrary client IPs without the needed privileges.","commonSituations":"Config templated from another node with different interfaces; IP removed/floated away (VRRP failover) while nginx kept running;容器/portability mistakes binding low ports; docker networks where the bound CIDR is not on the container interface.","solutions":["Verify the IP exists: ip addr show; if missing, add it (ip addr add 10.0.0.5/32 dev eth0) or fix the directive to an address on the host","If EADDRINUSE, pick a free port or (UDP case) rely on SO_REUSEADDR sharing nginx already attempts","If EACCES on a low port, grant CAP_NET_BIND_SERVICE to the binary (setcap cap_net_bind_service+ep) or switch to a high port","Reload nginx after interface changes so the bind target is valid"],"exampleFix":"# before: bind fails, EADDRNOTAVAIL — IP not on this host\nproxy_bind 10.0.0.5;\n\n# after: add the address, or bind to an address that exists\n# shell: ip addr add 10.0.0.5/32 dev eth0\nproxy_bind 10.0.0.5;   # now valid","handlingStrategy":"validation","validationCode":"# preflight every proxy_bind target: address must exist locally, port must be bindable\nfor addr in $(nginx -T 2>/dev/null | sed -n 's/.*proxy_bind \\([^ ;]*\\);.*/\\1/p' | grep -v '\\$' | sed 's/:.*//'); do\n  ip -o addr show | grep -qw \"$addr\" || echo \"MISSING local IP: $addr\"\ndone","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Attach a config-deploy hook that verifies each static proxy_bind IP exists (ip addr show) and the port is free","After VRRP/interface changes, reload nginx so binds target live addresses","Low ports need CAP_NET_BIND_SERVICE (setcap) — bake the setcap step into package/upgrade automation"],"tags":["nginx","network","bind","proxy-bind","address-in-use","capabilities"],"backgroundTag":"bind-failed","analyzedSha":"3f6f7824d4e2eb1ac37dec76683d525ac0ff521c","analyzedAt":"2026-08-22T03:09:46.447Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}