111 nginx network_error ai_generated true

connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.1, server: example.com, upstream: "http://127.0.0.1:8080"

ID: nginx/upstream-server-refused-connection

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2024-09-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx 1.24.0 active — — —
nginx 1.22.1 active — — —
nginx 1.20.2 active — — —

Root Cause

The upstream server is not listening on the specified port or IP, either because it is not running or is bound to a different address.

generic

中文

上游服务器未在指定端口或 IP 上监听,可能是因为它未运行或绑定到了不同的地址。

Official Documentation

https://nginx.org/en/docs/http/ngx_http_upstream_module.html

Workarounds

  1. 95% success Verify the upstream service is running: `sudo systemctl status myapp` or `netstat -tlnp | grep 8080`. Start it if needed: `sudo systemctl start myapp`.
    Verify the upstream service is running: `sudo systemctl status myapp` or `netstat -tlnp | grep 8080`. Start it if needed: `sudo systemctl start myapp`.
  2. 90% success Check if the upstream is listening on a different interface (e.g., 0.0.0.0 vs 127.0.0.1). Update the proxy_pass directive to match the actual listening address.
    Check if the upstream is listening on a different interface (e.g., 0.0.0.0 vs 127.0.0.1). Update the proxy_pass directive to match the actual listening address.
  3. 85% success If using a Unix socket, ensure the socket file exists and has correct permissions. Example: `ls -la /var/run/myapp.sock` and adjust nginx upstream to `server unix:/var/run/myapp.sock;`
    If using a Unix socket, ensure the socket file exists and has correct permissions. Example: `ls -la /var/run/myapp.sock` and adjust nginx upstream to `server unix:/var/run/myapp.sock;`

中文步骤

  1. Verify the upstream service is running: `sudo systemctl status myapp` or `netstat -tlnp | grep 8080`. Start it if needed: `sudo systemctl start myapp`.
  2. Check if the upstream is listening on a different interface (e.g., 0.0.0.0 vs 127.0.0.1). Update the proxy_pass directive to match the actual listening address.
  3. If using a Unix socket, ensure the socket file exists and has correct permissions. Example: `ls -la /var/run/myapp.sock` and adjust nginx upstream to `server unix:/var/run/myapp.sock;`

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Connection refused is an immediate TCP error; timeout does not help.

  2. 70% fail

    The error is about TCP connection, not URI path issues.

  3. 80% fail

    Nginx is working fine; the upstream service is down or misconfigured.