Serve a custom 404 page generated by PHP
nginx is doing this because you told it to.
fastcgi_intercept_errors on;
This means that nginx will not serve error responses generated by PHP, but have nginx handle them instead. Thus you get into your endless loop.
To resolve the problem, remove this directive (it defaults to off
) or set it explicity to off
.