Ошибка 104 connection reset by peer

Здравствуйте.
Ubuntu 16, FastCGI (Nginx + PHP-FPM), PHP 7.2.

Со вчерашнего дня сайт периодически выдает 502 ошибку, в лог пишет:

2018/09/02 08:41:18 [error] 7016#7016: *7584 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: xx.xxx.xxx.xxx, server: site.com, request: "GET /page/url/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "site.com"

Мой конфиг:

user www-data;
worker_processes auto;
worker_rlimit_nofile 65000;
timer_resolution 100ms;
worker_priority -5;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
	worker_connections 4096;
	multi_accept on;
	use epoll;
}

http {
	include      /etc/nginx/mime.types;
	default_type application/octet-stream;

	log_format main '$remote_addr - $remote_user [$time_local] "$request" '
					'$status $body_bytes_sent "$http_referer" '
					'"$http_user_agent" "$http_x_forwarded_for"';

	access_log /var/log/nginx/access.log main;

	sendfile on;
	keepalive_timeout 65;

	reset_timedout_connection on;

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/vhosts/*/*.conf;

	client_body_buffer_size 8m;
	client_max_body_size    128m;

	open_file_cache max=200000 inactive=20s; 
	open_file_cache_valid 30s; 
	open_file_cache_min_uses 2;
	open_file_cache_errors on;

	server {
		server_name      localhost;
		disable_symlinks if_not_owner;

		include /etc/nginx/vhosts-includes/*.conf;

		location @fallback {
			error_log /dev/null crit;

			proxy_pass http://127.0.0.1:8080;
			proxy_redirect http://127.0.0.1:8080 /;
			proxy_set_header Host $host;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto $scheme;

			access_log off ;
		}

		listen 80;
		listen [::]:80;
	}
}

И второй конфиг:

server {
	server_name site.com www.site.com;
	charset UTF-8;
	index index.php;
	disable_symlinks if_not_owner from=$root_path;
	include /etc/nginx/vhosts-includes/*.conf;
	include /etc/nginx/vhosts-resources/site.com/*.conf;
	error_log /var/www/httpd-logs/site.com.error.log crit;
	ssi on;
	return 301 https://$host:443$request_uri;
	set $root_path /var/www/www-root/data/www/site.com;
	root $root_path;
	gzip on;
	gzip_comp_level 5;
	gzip_disable "msie6";
	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
	error_log /var/www/httpd-logs/site.com.error.log notice;
	location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|ico)$ {
		expires 7d;
	}
	location / {
		try_files $uri /index.php?do=$uri;
		location ~ [^/]\.ph(p\d*|tml)$ {
			try_files /does_not_exists @php;
		}
	}
	location @php {
		fastcgi_index index.php;
		fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f znleha@yandex.ru";
		fastcgi_pass unix:/run/php/php7.2-fpm.sock;
		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
		try_files $uri =404;

		fastcgi_buffers 4 512k;
		fastcgi_busy_buffers_size 512k;
		fastcgi_temp_file_write_size 512k;

		include fastcgi_params;
	}
	access_log off;
	listen 77.222.63.224:80 default_server;
	listen [2a02:408:7722:54:77:222:63:224]:80 default_server;
}
server {
	server_name site.com www.site.com;
	ssl_certificate "/var/www/httpd-cert/www-root/site.com_le1.crtca";
	ssl_certificate_key "/var/www/httpd-cert/www-root/site.com_le1.key";
	ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
	ssl_prefer_server_ciphers on;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	add_header Strict-Transport-Security "max-age=31536000;";
	ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
	charset UTF-8;
	index index.php;
	disable_symlinks if_not_owner from=$root_path;
	include /etc/nginx/vhosts-includes/*.conf;
	include /etc/nginx/vhosts-resources/site.com/*.conf;
	error_log /var/www/httpd-logs/site.com.error.log crit;
	ssi on;
	set $root_path /var/www/www-root/data/www/site.com;
	root $root_path;
	gzip on;
	gzip_comp_level 5;
	gzip_disable "msie6";
	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
	error_log /var/www/httpd-logs/site.com.error.log notice;
	listen [2a02:408:7722:54:77:222:63:224]:443 ssl default_server;
	listen 77.222.63.224:443 ssl default_server;
	location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|ico)$ {
		expires 7d;
	}
	location / {
		try_files $uri /index.php?do=$uri;
		location ~ [^/]\.ph(p\d*|tml)$ {
			try_files /does_not_exists @php;
		}
	}
	location @php {
		fastcgi_index index.php;
		fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f znleha@yandex.ru";
		fastcgi_pass unix:/run/php/php7.2-fpm.sock;
		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
		try_files $uri =404;

		fastcgi_buffers 4 512k;
		fastcgi_busy_buffers_size 512k;
		fastcgi_temp_file_write_size 512k;

		include fastcgi_params;
	}
	access_log off;
}

Ошибка может появиться в любой момент (может и не появиться)… От куда ноги растут, не пойму…
Подскажите, куда копать?
Спасибо.

We’re developing a Python web service and a client web site in parallel. When we make an HTTP request from the client to the service, one call consistently raises a socket.error in socket.py, in read:

(104, 'Connection reset by peer')

When I listen in with wireshark, the «good» and «bad» responses look very similar:

  • Because of the size of the OAuth header, the request is split into two packets. The service responds to both with ACK
  • The service sends the response, one packet per header (HTTP/1.0 200 OK, then the Date header, etc.). The client responds to each with ACK.
  • (Good request) the server sends a FIN, ACK. The client responds with a FIN, ACK. The server responds ACK.
  • (Bad request) the server sends a RST, ACK, the client doesn’t send a TCP response, the socket.error is raised on the client side.

Both the web service and the client are running on a Gentoo Linux x86-64 box running glibc-2.6.1. We’re using Python 2.5.2 inside the same virtual_env.

The client is a Django 1.0.2 app that is calling httplib2 0.4.0 to make requests. We’re signing requests with the OAuth signing algorithm, with the OAuth token always set to an empty string.

The service is running Werkzeug 0.3.1, which is using Python’s wsgiref.simple_server. I ran the WSGI app through wsgiref.validator with no issues.

It seems like this should be easy to debug, but when I trace through a good request on the service side, it looks just like the bad request, in the socket._socketobject.close() function, turning delegate methods into dummy methods. When the send or sendto (can’t remember which) method is switched off, the FIN or RST is sent, and the client starts processing.

«Connection reset by peer» seems to place blame on the service, but I don’t trust httplib2 either. Can the client be at fault?

** Further debugging — Looks like server on Linux **

I have a MacBook, so I tried running the service on one and the client website on the other. The Linux client calls the OS X server without the bug (FIN ACK). The OS X client calls the Linux service with the bug (RST ACK, and a (54, ‘Connection reset by peer’)). So, it looks like it’s the service running on Linux. Is it x86_64? A bad glibc? wsgiref? Still looking…

** Further testing — wsgiref looks flaky **

We’ve gone to production with Apache and mod_wsgi, and the connection resets have gone away. See my answer below, but my advice is to log the connection reset and retry. This will let your server run OK in development mode, and solidly in production.

Nginx 502 is an uncommon error that causes due to issue with your server Nginx and PHP-FastCGI. If you notice any Nginx 502 error it is better to check the Nginx log.

When you are investigating the Nginx error logs, you can see that the “recv() failed (104: Connection reset by peer) while reading response header from upstream,” error. This also results in a “no live upstreams while connecting to upstream” error. 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.

There are mainly three different reasons for Nginx Connection reset by peer.

  • Nginx and PHP-FPM communication error.
  • PHP-FPM is timing out quickly.
  • PHP-FPM is not running.

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 a managed hosting package, you can ask your hosting partner to correct that configuration file.

Nginx logo

Table of Contents

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 are 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.

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 the Nginx conf file.

PHP-FPM Configuration

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

Check PHP permission for session.save_path.

In some situations, your PHP is not able to write the season file. This will generate Nginx 502 connection reset by peer while reading response header from upstream.

There can be several reasons for PHP is not able to write the season file. It can be bad permissions, bad directory ownership, or even bad user/group.

  • First check where your PHP session.save_path is. Some situations it is “/var/lib/php/sessions” or “/var/lib/php/session
  • Open your system php.ini file and search for “session.save_path“.
  • Then you can see your system PHP session.save_path.
  • Run the following command in your SSH terminal to fix the permission issue. In this example my LEMP stack php session.save_path is “/var/lib/php/session
  • Then restart php.

Change FastCGI Timeouts.

Another solution is to change the Nginx Fast-CGI timeouts. Default FastCGI timeout is the 60s. Your application may require higher than the 60s to run, therefore it is better to change the following timeouts to prevent Nginx 502 bad gateway error.

  • Open the nginx configuration file. Generally it is “/etc/nginx/nginx.conf“.
  • Change add the following timeout values to your nginx.conf.
      • fastcgi_read_timeout 300;
      • fastcgi_send_timeout 300;
      • fastcgi_connect_timeout 300;
  • Save the changes and restart nginx.

Increase opcache memory limit.

If your system PHP uses opcache if the opcache memory gets filled, it will show connection reset by peer while reading response header from upstream. The simple solution is to increase the opcache memory limit.

  • Open the php.ini file.
  • Search for “opcache.memory_consumption”.
  • Change the value to a higher amount like below.

opcache.memory_consumption = 256

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

When you are attempting to log into any website, you get Error 104 Connection Reset by Peer shows like, ‘The Information you have entered is not valid.’ So, if you are getting or facing this type of error code problem, you must check out this post once sufficiently to get the best and right solutions for your this error problem. So check out,

It shows an error code message like,

Error 104

This webpage is not available

The webpage might be temporarily down, or it may have moved permanently to a new web address.

Error 104 (net::ERR_CONNECTION_FAILED). The attempt to connect to the server failed.

This error may occur when your PC or the router cannot find the internet connection. This error may also result in a fault in the router’s settings or the modem. It is mainly found on the D-Link router & modems. It is a standard error that most users face. & it mostly showed in the google chrome browser. This Error Code 104 includes PC crashes, freezes & malware, or virus infection.

Causes of Error 104 Connection Reset by Peer Issue:

  • Connection reset by peer
  • Windows PC error problem
  • Google Chrome Browser error issue

So, here are the guide and some solutions for fixing and solving this type of Error 104 Connection Reset by Peer problem from you completely.

How to Fix Error 104 Connection Reset by Peer Windows Issue

1. Clear your Internet Browser Cache & Cookies on your PC –

Clear your Browsing Data cookies and cache

  • Go to your Browser
  • Click on the Settings tab or click on the History option
  • Go to the “Clear Browsing Data” option there
  • Tick the ‘Cookies‘ and ‘Caches‘ options there
  • If you want any more to delete, then tick that option too
  • Now click on their drop-down menu
  • Select the ‘from the beginning‘ option there
  • Now, click on the “Clear Browsing Data” button there
  • Wait for some minutes to delete it
  • Now, close the tab
  • That’s it, done

Clearing your browser’s browsing data can eliminate this WebEx Error 104 (connection reset by peer) problem from you.

2. Run a Full Scan of your Windows PC for Viruses/Malware –

Scan your PC for Virus/Malware - Error 104

  • Go to the start menu.
  • Search or go to the “Microsoft Security Essentials” there
  • Click on it and opens it there
  • A Pop-up will open there
  • Check the ‘Full‘ option there to scan thoroughly
  • After, click on the ‘Scan Now‘ option to scan carefully
  • After scanning, close the tab
  • That’s it, done

Running a full scan of your PC can completely eliminate this Error 104 Connection reset by peer problem from your PC.

3. Uninstall the Unwanted Extensions from your Internet Browser –

Uninstall unwanted Extensions from your Browser

  • Go to the start menu
  • Search or go to your Browser
  • Click on it and opens it there
  • After that, click on the three dots signs there
  • & click on ‘More Tools‘ there
  • Now, click on the ‘Extensions‘ option there
  • Click on the extension which you do not want (Unwanted)
  • Click on the Trash sign there to remove it from the browser
  • After removing, close the tab
  • That’s it, done

Uninstalling unwanted extensions from your browser can quickly fix and solve this pad error 104 Netflix problems from your PC browsers.

4. Do a Windows Disk CleanUp on your PC –

Run a Disk Cleanup of your PC Error 104

  • Go to the start menu
  • Search or go to the Disk Cleanup
  • Opens it and after that
  • Select the Disk you want to clean
  • Now, tick & select the options which you want to clean it
  • Wait for some minutes to clean
  • After completing, close the tab
  • That’s it, done

Running a disk cleanup of your full PC can quickly fix and solve this Error 104 Connection reset by peer problem from your PC.

5. Create a System Restore Point on your Windows PC –

Fix System Restore Features

  • Go to the start menu
  • Search or go to the ‘System Restore.’
  • Clicks on it and open it there
  • After that, tick on the “Recommended settings” or ‘Select a restore point‘ there.
  • After selecting, click on the Next option there
  • Now, follow the wizard
  • After completing, close the tab
  • That’s it, done

By trying this guide and tips from here, you will eliminate this pad Error 104 problem issue.

OR

Run System Restore & Create a Restore Point Error 104

  • Go to the start menu
  • Search or go to the ‘System Properties.’
  • Click on it and opens it.
  • After that, go to the “System Protection” option there
  • Now, click on the “System Restore” option there
  • & Create a Restore point there
  • After completing, close the tab
  • That’s it, done

Running a system restore and creating a new restore point by any of these two methods can completely solve this Error 104 Netflix problem from your PC.

Conclusion:

These are some tips and guides for permanently removing this Error 104 Connection Reset by Peer problem from you. Hopefully, these solutions will help you get back from this Error 104 problem.

If you are facing any Error 104 Connection Reset by Peer problem or any problem while fixing it, then comment down the error problem below so that we can fix and solve it too by our quick guide solutions.

Это одна из тех ошибок, которая является причиной появления ответов Bad Gateway с 502 кодом на сайтах. Но что является истинной причиной проблемы и как ещё устранить? Итак, если в журнальных файлах /var/log/nginx/error.log вы обнаружили что-то подобное:

2018/10/05 06:28:17 [error] 3111#0: *54528 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: ip.ip.ip.ip, server: site.com  request: ""GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "site.com"

Это означает, что nginx не смог получить от php-fpm вразумительного ответа. Чаще всего это происходит в результате каких-то ошибок в скриптах, а в некоторых случаях причиной проблемы может стать сам php либо одна их его библиотек содержащих ошибку и приводящая к вылету php-скрипта посредине обработки.

В первую очередь нужно проверить логи PHP, а если их нет — включить максимальный уровень логирования. Затем попытайтесь устранить ошибку указанную в логах.


Post Views:
9 846

Понравилась статья? Поделить с друзьями:
  • Ошибка 103 при установке драйвера сетевой карты
  • Ошибка 103 при установке драйвера звуковой карты
  • Ошибка 103 при установке драйвера видеокарты amd
  • Ошибка 103 при установке драйвера sdi
  • Ошибка 103 при установке драйвера intel