Nginx 404, 500 errors and WordPress

Warning

Before you get started, I highly recommend you to create a child theme to safely modify the current theme you’re using. That way, if you need to update your theme, your changes won’t be overwritten.

Modifying your current error page

If your theme already has a custom error page, look for a 404.php file in your theme’s root directory (/wp-content/themes/your-theme/404.php) and copy it into your child theme’s folder under (/wp-content/themes/your-theme-child/404.php). Modify this to your liking.

Creating an error page

If your theme doesn’t have a 404 error page set up, you could create one, but instead of creating an error page from scratch, you could copy your theme’s page.php file to your child theme directory and rename it 404.php (/wp-content/themes/your-theme-child/404.php) and modify this to your liking.

If you want to cover any other types of errors / HTTP Status Codes repeat the steps above and just rename the file to reflect the type of error page you want to create such as 404.php or 403.php.

See a list of HTTP Status Codes:

If you are unable to create a child theme or don’t want to create one, you could always use a plugin: https://wordpress.org/plugins/404page/

Sources:

NGINX
Nginx is not my expertise, I use Apache. So bear with me:

# define error page
error_page 404 = @notfound;

# error page location redirect 302
location @notfound {
    return 404 /custom-error-page;
}

In your php block put the fastcgi_intercept_errors set to on

location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    # intercept errors for 404 redirect
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

See for more information: https://guides.wp-bullet.com/nginx-redirect-404-errors-to-homepage-wordpress/