nginx: connect() failed (111: Connection refused) while connecting to upstream - after update nginx -

nginx: connect() failed (111: Connection refused) while connecting to upstream - after update nginx -

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

nginx: connect() failed (111: Connection refused) while connecting to upstream - after update nginx -

Upgrading your reverse proxy or web server is a routine maintenance task, but version updates can sometimes expose configuration mismatches that were previously hidden. When you upgrade Nginx from an older stable release to version 1.19 and suddenly encounter 502 Bad Gateway errors with the specific log message connect() failed (111: Connection refused) while connecting to upstream, it is rarely a bug in the new binary. Instead, it is almost always a symptom of how Nginx handles process forking and socket ownership has changed or become stricter between versions.

The error log entry you are seeing provides the critical diagnostic data needed to resolve the issue:

2021/03/24 06:25:50 [error] 56837#56837: *7775 connect() failed (111: Connection refused) while connecting to upstream, client: 85.208.98.19, server: bienestarmutuo.org, request: "GET /ten-principles-of-the-new-education/ HTTP/1.1", upstream: "fastcgi://10.64.10.43:8050", host: "mutualwelfare.org"

The core issue here is Connection refused. This is an ECONNREFUSED error returned by the kernel when a process attempts to connect to a TCP port on a specific IP address, and no process is listening on that socket. In your case, Nginx (running on 85.208.98.19 or similar) is trying to talk to an upstream FastCGI server at 10.64.10.43:8050. The connection fails immediately because nothing is accepting connections on port 8050 of that upstream host.

However, there is a specific nuance introduced in Nginx 1.19 regarding how worker processes handle file descriptors and socket ownership after a systemd restart or an upgrade. In older versions of Nginx, the master process might have inherited sockets or handled certain cleanup tasks differently than the new default behavior. If your application running on 10.64.10.43 (likely PHP-FPM or another FastCGI processor) is configured to run as a different user than Nginx expects, or if the socket binding permissions were tightened during the upgrade, the upstream service might be starting but refusing connections from the Nginx master process due to SELinux contexts or file descriptor inheritance issues.

To troubleshoot this effectively without blindly restarting services, you must verify the state of the upstream listener first. Log into the host running the upstream application (10.64.10.43). Run netstat -tlnp or ss -tlnp to confirm that a process is actually listening on port 8050:

ss -tlnp | grep 8050

If this command returns nothing, the application itself failed to start during the upgrade sequence. Check the application logs on that host for startup errors. If the service is running but you still get a connection refused from Nginx, inspect the socket permissions and file descriptor limits. Nginx worker processes sometimes cannot connect to local sockets if they lack the necessary permissions or if the upstream is listening on localhost (127.0.0.1) while Nginx tries to connect via a different interface or loopback context.

Another common pitfall after upgrading Nginx involves the fastcgi_pass directive configuration. Ensure that the path specified in your nginx.conf matches exactly what the upstream is listening on. If you upgraded from a version where listen 8050; implied all interfaces, to a stricter environment where it implies only IPv4 or localhost, the connection logic changes. Additionally, verify that no bind directive restrictions exist on the upstream service preventing external connections.

If you are deploying this setup within a containerized environment or using systemd services, ensure that the socket activation units are correctly configured for the new Nginx version. The upgrade to 1.19 may have altered default resource limits or signal handling which could cause the master process to fail to pass sockets to workers correctly in specific high-concurrency scenarios, though Connection refused usually points to a listening service issue rather than a worker failure (which would typically show as ECONNRESET or timeout).

For developers managing legacy integrations, it is often necessary to explicitly define the upstream protocol and verify that the upstream server's security policies allow incoming connections from the Nginx IP range. If you are using a shared hosting environment or a cloud provider, check firewall rules on the upstream host; an update to the OS or kernel might have reset iptables rules, inadvertently blocking traffic from the Nginx instance.

Finally, if this setup involves Laravel applications or similar PHP stacks, ensure that your php-fpm pool configuration aligns with the Nginx upgrade. Sometimes, upgrading the web server while keeping an older version of the PHP runtime can lead to binary incompatibilities in socket handling. Always restart the upstream service after an Nginx upgrade to ensure it picks up any new environment variables or configuration changes related to network binding:

systemctl restart php-fpm
# OR
service php-fpm restart

By systematically verifying the listening state of the upstream, checking file descriptor inheritance, and ensuring firewall rules are consistent with the new Nginx version's stricter default policies, you can resolve the Connection refused error and restore your gateway functionality.

Our network