Nginx return 404 custom in IF statement

I configured my page 404

error_page 404 /erreur/404;

Everything works well, except when I return 404 in if statement, I get the 404 not found by Nginx,not my custom page.

My code:

location ~ \.php$ 
    if ($request_uri ~* \.php) # Block direct acces to [files].php
        return 404;

    fastcgi_intercept_errors on;
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;