I'm trying to use a custom 404.php page for 404 errors instead of the default nginx error page, but everything I tried so far won't work. I can serve a custom 404.html page with no problems, but can't get it to work for php. The following is what I tried in my default config with no luck.
error_page 404 /404.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_intercept_errors on;
}
I also tried
error_page 404 = /404.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_intercept_errors on;
}
I'm using nginx/1.10.3 (Ubuntu)
root /var/www/html;andinternal;afterinclude snippets/fastcgi-php.conf;