rewrite with nginx conf result 502 bad gateway
The location of file phpfpm.sock may vary depending on Operating System:

Try find the phpfpm.sock file on your server:

find / -name php*fpm.sock


and then change the following line

fastcgi_pass unix:/tmp/phpfpm.sock;


to reference phpfpm.sock from the correct location.

Example (Ubuntu 14):

fastcgi_pass unix:/var/run/php5-fpm.sock;