title: Connection reset by peer - while reading response header from upstream using nginx and php-fpm7.2
body: <p><strong>Below is the error log:</strong></p>
  
  <p>nginx </p>
  
  <blockquote>
    <p>[error] 6518#6518: *1548 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 106.51.134.160, server: example.com, request: "POST /api/example HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "example.com"</p>
  </blockquote>
  
  <p><strong>php7.2-fpm.log</strong> </p>
  
  <blockquote>
    <p>[error] 6518#6518: *1548 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 106.51.134.160, server: api.onsurity.com, request: "POST /api/example HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "example.com"</p>
  </blockquote>
  
  <p><strong>I have increased the timeout and size in nginx.conf</strong> </p>
  
  <pre><code>client_body_in_file_only clean;
  client_body_buffer_size 32K;
  client_max_body_size 200M;
  sendfile on;
  send_timeout 300s;
  fastcgi_read_timeout 600s;
  </code></pre>
  
  <p><strong>Another solution mentioned to increase the request time out and other limits in php.ini</strong> </p>
  
  <pre><code>upload_max_filesize=2000M
  max_file_uploads=2000
  memory_limit=128M
  post_max_size=8000M
  request_terminate_timeout = 300s
  </code></pre>
  
  <p>It is showing 502 gateway error while hitting the post request containing base64 image array. Approx. size would be 6MB</p>