1

When I try to access a certain page on my server, it returns with a 502 Gateway error. (Sometimes it works but then I reload the page and it shows the 502 Gateway page again).

If I check the nginx error logs, this error comes up:

2017/09/13 19:14:49 [error] 3762#3762: *22 upstream prematurely closed FastCGI stdout while reading response header from upstream, client: serverip, server: localhost, request: "GET /inventory.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "localhost", referrer: "localhost"

I tried looking up the error on google, but no solutions so far, and was wondering if someone knows what the error is & how to fix it.

Thanks.

Edit 1:

  • fastcgi_buffers are set to this:

fastcgi_buffers 16 16k;

fastcgi_buffer_size 120k;

1
  • How dynamic is this page? i.e, is it possible php is running into an error and closing stdout on only some requests?
    – pucky124
    Sep 13, 2017 at 20:21

2 Answers 2

2

I used below code in my nginx configuration and reload nginx, solved my issue -

fastcgi_buffers 16 16k;
fastcgi_buffer_size 120k;
0

Try to increase values of the next settings:

fastcgi_buffer_size
fastcgi_buffers

https://nginx.ru/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_buffer_size https://nginx.ru/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_buffers

2
  • I increased them, restarted nginx but still throws the 502 error. Any idea how far i should increase them? Added an edit to the original post.
    – Love2Code
    Sep 13, 2017 at 20:01
  • Depends on what size of the fastcgi answer. Also you should look at the php error log.
    – Talgat
    Sep 13, 2017 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.