Error pages not working for .php extension

If the request is for a .php file that isn’t found I get “File not found.” if it is for any other type of file .html for example it goes to the correct 404 page.

I must have done something wrong in the configuration so any advice would be great.

The website uses my own php system. This is something that has happened since migrating my server from and old centos / cpanel to a unbuntu / hestia setup.

If you show the nginx conf for your domain we could take a look.

I’m using apache as a web server. The error pages are configured through the .htaccess file.

I didn’t think I was using nginx

I’ve certainly not modified the default configuration of nginx.

The web address is: https://betterthanapokeintheeye.co.uk

If I go to https://betterthanapokeintheeye.co.uk/banana.html it goes to the correct 404 page.

If I instead go to https://betterthanapokeintheeye.co.uk/banana.php it says File not found.

I can upload the nginx.conf file if you like. That’s the one in /etc/nginx

No, you should upload the nginx conf files for your domain:

/etc/nginx/conf.d/domains/betterthanapokeintheeye.co.uk.conf
/etc/nginx/conf.d/domains/betterthanapokeintheeye.co.uk.ssl.conf
#=========================================================================#
# Default Web Domain Template                                             #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS   #
# https://hestiacp.com/docs/server-administration/web-templates.html      #
#=========================================================================#

server {
	listen      45.8.225.231:80;
	server_name betterthanapokeintheeye.co.uk www.betterthanapokeintheeye.co.uk betterthanapokeintheeye.uk www.betterthanapokeintheeye.uk;
	error_log   /var/log/apache2/domains/betterthanapokeintheeye.co.uk.error.log error;

	include /home/betterthan/conf/web/betterthanapokeintheeye.co.uk/nginx.forcessl.conf*;

	location ~ /\.(?!well-known\/|file) {
		deny all;
		return 404;
	}

	location / {
		proxy_pass http://45.8.225.231:8080;

		location ~* ^.+\.(css|htm|html|js|json|xml|apng|avif|bmp|cur|gif|ico|jfif|jpg|jpeg|pjp|pjpeg|png|svg|tif|tiff|webp|aac|caf|flac|m4a|midi|mp3|ogg|opus|wav|3gp|av1|avi|m4v|mkv|mov|mpg|mpeg|mp4|mp4v|webm|otf|ttf|woff|woff2|doc|docx|odf|odp|ods|odt|pdf|ppt|pptx|rtf|txt|xls|xlsx|7z|bz2|gz|rar|tar|tgz|zip|apk|appx|bin|dmg|exe|img|iso|jar|msi|webmanifest)$ {
			try_files  $uri @fallback;

			root       /home/betterthan/web/betterthanapokeintheeye.co.uk/public_html;
			access_log /var/log/apache2/domains/betterthanapokeintheeye.co.uk.log combined;
			access_log /var/log/apache2/domains/betterthanapokeintheeye.co.uk.bytes bytes;

			expires    max;
		}
	}

	location @fallback {
		proxy_pass http://45.8.225.231:8080;
	}

	location /error/ {
		alias /home/betterthan/web/betterthanapokeintheeye.co.uk/document_errors/;
	}

	include /home/betterthan/conf/web/betterthanapokeintheeye.co.uk/nginx.conf_*;
}
#=========================================================================#
# Default Web Domain Template                                             #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS   #
# https://hestiacp.com/docs/server-administration/web-templates.html      #
#=========================================================================#

server {
	listen      45.8.225.231:443 ssl;
	server_name betterthanapokeintheeye.co.uk www.betterthanapokeintheeye.co.uk betterthanapokeintheeye.uk www.betterthanapokeintheeye.uk;
	error_log   /var/log/apache2/domains/betterthanapokeintheeye.co.uk.error.log error;

	ssl_certificate     /home/betterthan/conf/web/betterthanapokeintheeye.co.uk/ssl/betterthanapokeintheeye.co.uk.pem;
	ssl_certificate_key /home/betterthan/conf/web/betterthanapokeintheeye.co.uk/ssl/betterthanapokeintheeye.co.uk.key;
	ssl_stapling        on;
	ssl_stapling_verify on;

	# TLS 1.3 0-RTT anti-replay
	if ($anti_replay = 307) { return 307 https://$host$request_uri; }
	if ($anti_replay = 425) { return 425; }

	include /home/betterthan/conf/web/betterthanapokeintheeye.co.uk/nginx.hsts.conf*;

	location ~ /\.(?!well-known\/|file) {
		deny all;
		return 404;
	}

	location / {
		proxy_pass https://45.8.225.231:8443;

		location ~* ^.+\.(css|htm|html|js|json|xml|apng|avif|bmp|cur|gif|ico|jfif|jpg|jpeg|pjp|pjpeg|png|svg|tif|tiff|webp|aac|caf|flac|m4a|midi|mp3|ogg|opus|wav|3gp|av1|avi|m4v|mkv|mov|mpg|mpeg|mp4|mp4v|webm|otf|ttf|woff|woff2|doc|docx|odf|odp|ods|odt|pdf|ppt|pptx|rtf|txt|xls|xlsx|7z|bz2|gz|rar|tar|tgz|zip|apk|appx|bin|dmg|exe|img|iso|jar|msi|webmanifest)$ {
			try_files  $uri @fallback;

			root       /home/betterthan/web/betterthanapokeintheeye.co.uk/public_html;
			access_log /var/log/apache2/domains/betterthanapokeintheeye.co.uk.log combined;
			access_log /var/log/apache2/domains/betterthanapokeintheeye.co.uk.bytes bytes;

			expires    max;
		}
	}

	location @fallback {
		proxy_pass https://45.8.225.231:8443;
	}

	location /error/ {
		alias /home/betterthan/web/betterthanapokeintheeye.co.uk/document_errors/;
	}

	proxy_hide_header Upgrade;

	include /home/betterthan/conf/web/betterthanapokeintheeye.co.uk/nginx.ssl.conf_*;
}

Hi @RincewindOook,

Let’s try this (if it works, we will modify the apache template that is using your site):

Edit /etc/apache2/apache2.conf file and add the directive ProxyErrorOverride On

You will get something like this:

[...]

PidFile ${APACHE_PID_FILE}
Timeout 30
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 10
ProxyErrorOverride On    <--- this is the line you need to add

[...]

Once modified, restart or reload apache2 and try again.

systemctl restart apache2

2 Likes

Thank you that worked.

2 Likes

Is this to make it permanent? I assume the /etc/apache2/apache2.conf is likely to be overwritten on an update.

Yeah that was just to test whether it works.

You should create a new template for apache (so it won’t be replaced in next update) and edit your web domain to assign that template.

As root:

Note: discworld is just an example, use the template name you prefer.

cd /usr/local/hestia/data/templates/web/apache2/php-fpm/
cp default.tpl discworld.tpl
cp default.stpl discworld.stpl

Now edit both files and add the directive ProxyErrorOverride after ErrorLog

Like this (in both files):

[...]
    CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
    CustomLog /var/log/%web_system%/domains/%domain%.log combined
    ErrorLog /var/log/%web_system%/domains/%domain%.error.log
    ProxyErrorOverride On
[...]

Once done, edit your web domain and in Apache Template select discworld and Save

Now you can remove the directive previously added to /etc/apache2/apache2.conf and restart apache

systemctl restart apache2
1 Like

Thank you.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.