if the error log say :
… upstream sent too big header while reading response header from upstream …
then add in the nginx conf file of the app :
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
then verify the nginx conf
conf -t
if everything is ok, then reload nginx
service nginx reload
[source : http://www.dj-j.net/waka/Linux:Nginx_Erreur_502_Fastcgi_PHP ]