Software⏱️ 2 min read📅 2026-05-31

How to Fix: connect() failed (111: Connection refused) while connecting to upstream

Nginx configuration issue causing 502 Gateway error.

Quick Answer: Check the fastcgi_pass directive in your nginx.conf file to ensure it's pointing to a valid PHP process manager, such as php-fpm.

The 'connect() failed (111: Connection refused)' error occurs when the PHP script cannot establish a connection to the fastcgi server. This is often due to the fact that the fastcgi process is not running or not listening on the specified port.

🔍 Why This Happens

  • [Cause]

🚀 How to Resolve This Issue

Method 1: Check and Restart Fastcgi Process

  1. Step 1: Open your terminal and run the command `sudo service php7.4-fpm restart` (or the equivalent command for your PHP version) to restart the fastcgi process.

Method 2: Configure Nginx to Use a Different Port

  1. Step 1: Open your nginx.conf file in a text editor and update the 'fastcgi_pass' directive to point to a different port, for example: fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

✨ Wrapping Up

To resolve the 'connect() failed (111: Connection refused)' error, you can try restarting the fastcgi process or configuring Nginx to use a different port. If neither method works, you may need to investigate further to determine the cause of the issue.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions