If after configuring nginx and php-fpm to work through php5-fpm.sock, Nginx throws a 502 bad gateway error and the log contains something like this:
*20 connect() to unix:/usr/local/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream
Then the permissions problem can be fixed like this:
cd /usr/local/var/run
sudo chmod 666 php5-fpm.sock
If that helped, then in /usr/local/etc/php/5.5/php-fpm.conf you should also uncomment this line:
listen.mode = 0666