Fix Nginx 104: Connection Reset By Peer While Reading Response Header From Upstream

Nginx error logs show “recv() failed (104: Connection reset by peer) while reading response header from upstream,“. When I’m checking my WordPress site logs I saw that several times appeared that error log. This is an issue with the Nginx and PHP-FPM configurations. Can easily fix it in just a few steps.

In order to fix 104: Connection reset by peer while reading response header from upstream issue, you should have access to modify the PHP and Nginx configuration files. If you are on shared hosting or managed hosting package, you can ask from your hosting partner to correct that configuration file.

If you can see continuous connection reset by peer error your visitors may receive  “502 Bad Gateway” errors. To correct this Nginx error you must set Nginx keepalive_requests and PHP-FPM pm.max_requests equal value. If these two values not equal then the Nginx or PHP-FPM end up closing the connection. This is an issue caused by server configuration mismatch, you can fix it by like our Logrotate issue guide.

Nginx logo

How to Fix Connection Reset By Peer While Reading Response Header From Upstream.

Change Nginx keepalive_requests.

  • Open the nginx.conf configuration file with sudo privileges.

  • Change keepalive_requests as per your need. Don’t use too high keepalive_requests, it can cause excessive memory usage.

Edit Nginx Configuration

  • Save the configuration file.

Change PHP-FPM www.conf

  • Open the www.conf file with sudo privilege.

  • In “pm.max_requests” enter the same value you set on “keepalive_requests” in Nginx conf file.

PHP-FPM Configuration

  • Save the configuration file.
  • Restart the Nginx and PHP-FPM by running the following command line.

 

From now, your error should disappear and visitors can access your site without any error.

error: Content is protected !!