Laravel Valet 502 bad gateway - upstream sent too big header

Got a 502 bad gateway error?

First, check the Nginx logs located in ~/.config/valet/Log/nginx-error.log

The last error reveals an error that regards too big headers. By default the Nginx headers are quite small

upstream sent too big header while reading response header from upstream

Open usr/local/etc/nginx/nginx.conf and add this lines inside http {}

    fastcgi_buffers 16 16k; 
    fastcgi_buffer_size 32k;

And restart Valet: valet restart

Please note that in production you may want to properly determin the correct buffer size: https://gist.github.com/magnetikonline/11312172#determine-actual-fastcgi-response-sizes