Nginx + PHP-FPM = "Random" 502 Bad Gateway

I think your max_children is too low

<value name="max_children">3</value>

Also you can try switching from TCP port to unix socket for php-fpm:

php-fpm.conf

<value name="listen_address">/tmp/php.sock</value>

nginx.conf

fastcgi_pass unix:/tmp/php.sock;

Elaborated:

  1. Unix sockets are ~20% faster
  2. You don't use time-wait sockets for each connect