1

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)

10
  • Do you have static page 404.php? Commented Jul 23, 2018 at 11:25
  • @IgorCova I have a 404.php page in my root directory. /var/www/html/404.php Commented Jul 23, 2018 at 11:29
  • add rows root /var/www/html; and internal; after include snippets/fastcgi-php.conf; Commented Jul 23, 2018 at 11:31
  • @IgorCova I just tried that unfortunately it's still displaying the default nginx 404. Commented Jul 23, 2018 at 11:45
  • Did you do reload nginx? Commented Jul 23, 2018 at 11:46

1 Answer 1

5

Rewrite row in your conf file error_page 404 /404.php; to error_page 404 /404;

Check if your nginx.conf file included file conf of your site, that you described

Don't forget to reload nginx via command systemctl reload nginx after changes, and also you can check syntax via command nginx -t before reload

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.