Laravel On Cloudflare Produces 502 Bad Gateway On Form Errors

On my Laravel app, I have a form that is validated using standard Laravel validation. If it fails, it simply redirects back to the same form and displays the errors. This is working perfectly fine on my local machine as well as on the dev site (which is hosted on the same server as production).

However, in my production site, the error produces a 502 Bad Gateway page (rendered by CloudFlare).

enter image description here

The only difference that I can find between the dev & production (or staging) sites is the environment configuration (most notably APP_ENV). I would think this might be an error to do with SSL and redirecting, but the dev environment has the same SSL settings as the staging & production, but dev shows the errors on the page as it is supposed to be, whereas staging & production shows 502. I could not find anything in the nginx or Laravel error logs. I would like some direction if anyone has dealt with this, where to look, whether it's ngnix configuration, Cloudflare configuration, SSL configuration, or Laravel configuration.



This seemed to be solved with the following put in the nginx config:

fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;

So far no side effects, I will give it a few days to see that all functions well before confirming this as a fix.