0

I've been getting timeouts caused by a 502 bad gateway error on certain GET requests.

I've tried adding these lines to my nginx site conf file:

server {
    client_max_body_size 500M;
    client_header_timeout 3000;
    client_body_timeout 3000;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_read_timeout 3000;
        fastcgi_send_timeout 3000;
        fastcgi_connect_timeout 3000;
        fastcgi_buffers 128 256k;
        fastcgi_buffer_size 256k;
    }
}

I also tried tweaking the buffer sizes in the following ways:

fastcgi_buffers 256 512k;
fastcgi_buffer_size 512k;

fastcgi_buffers 64 128k;
fastcgi_buffer_size 128k;

fastcgi_buffers 32 64k;
fastcgi_buffer_size 64k;

I also tried changing PHP-FPM conf values to these:

max_execution_time = 3000
max_input_time = -1
memory_limit = 2048M
post_max_size = 500M
upload_max_filesize = 500M
opcache.memory_consumption = 1024

I also tried disabling OPCache.

So far none of this has alleviated the 502 error. Sometimes it times out at exactly 1 minute, sometimes it is 1.2 minutes according to the Chrome dev tools. I can't account for the variability in timeout.

When I check the site-specific nginx error log I see this error generated each time I try to access the URL:

[error] 20675#20675: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.72.213.137, server: example.com, request: "GET /data/123 HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.1-fpm.sock:", host: "example.com"

Am I missing some key setting?

PHP 7.1

nginx 1.13.3

  • Check your application. If it die()s then you also get a 502 Bad Gateway. – Michael Hampton Nov 8 '17 at 19:40
  • There are no errors produced in the PHP or Laravel framework logs. How could I tell if the app is dying unexpectedly if there are no app level errors? – eComEvo Nov 8 '17 at 19:46
  • @eComEvo force your app to return a 200 response and then exit. That should rule out application issues. – Reverend Tim Nov 10 '17 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.