nginx - 502 Bad Gateway for some ajax requests

ajax, nginx, php

Solution

I had similar problem on wordpress site. add these lines inside `http` block of `/etc/nginx/nginx.conf` file.

fastcgi_temp_file_write_size 10m;
fastcgi_busy_buffers_size 512k;
fastcgi_buffer_size 512k;
fastcgi_buffers 16 512k;

If it still not working also add this line

 client_max_body_size 50M;

Problem

I get 502 Bad Gateway for some requests on my server. I get it for some particular AJAX requests but if I replay the failed request in the console, it works (wtf). In `nginx/error.log` it says [error] 13867#0: *74180 recv() failed (104: Connection reset by peer) while reading response header from upstream My website is in PHP. Thanx

Original source