• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Issue error_page in additional nginx directives

groovyjon

Basic Pleskian
I can't seem to get the error_page directive working in nginx.

I have the following directive in the Apache settings which works fine when I go to a non-existent page/folder on the website:

ErrorDocument 404 /notfound.php

But if I try to go to a non-existent page with a .php extension then it just shows a "File not found" message.

I have put the following in the "additional nginx directives" but it has no effect:

error_page 404 /notfound.php;
location = /notfound.php {
root /var/www/vhosts/mydomain.com/httpdocs;
internal;
}

What am I doing wrong?

Running Plesk Onyx 17.5.3 Update #11 on Ubuntu 16.04.2 LTS
 
Similar to Question - Custom 404 error page if you useing nginx
where it is referred to Setting Up Custom Error Pages on Linux Servers

Is your PHP version set to "PHP-FPM served by Nginx"? I think the easiest workaround for the issue could be to change that setting to "PHP-FPM served by Apache", because it will then not even care what the Nginx configuration is, but Nginx will forward all .php requests to Apache. And as you say that your Apache config works, it could be a possible way to resolve it.
 
If it is set to Apache, Nginx forwards all dynamic requests to Apache.

Maybe the "not found" error does not result from the first file that is not found, but from the "notfound.php" file not found? That could be solved by providing a fully qualified URL instead of only the filename /notfound.php, for example
ErrorDocument 404 http://mydomain.tld/notfound.php
It is possible, too, that in your .htaccess file there is an additional ErrorDocument directive for the 404. That would override the directive you set in the Apache configuration section.

If that does not work, you could consider removing the directive in general and placing your 404 not found file into the error documents directory as described in Setting Up Custom Error Pages on Linux Servers Have you tried that?
 
The fully qualified URL didn't make any difference.

I haven't put any of my own .htaccess files on the server if that's what you mean in your second point.

I will look at the error documents directory method now.
 
However, the problem with using the error_docs directory is that it looks like I'm restricted to html files. I would like to have a PHP page displayed so it can include some other files too.
 
Hi groovyjon,

you could try to solve your issue with this additional apache modification:
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
    RewriteRule (.*) - [H=text/html]
</IfModule>
 
Back
Top