500 nginx error pages
In recent days I have been trying to get 500 pages to work, at first I used the exact same thing I used with 404 error but it didn't work and I think it is because it is a .php file
error_page 404 /errors/404.php;
error_page 500 502 503 504 /errors/500.php;
Is there a way to use a php file as a 500 error or do I need to create a "500.html" and copy all the code that looks like a page to the website?
To create a 500 error, I used:
fastcgi_pass unix:/var/run/php-fpm/php-fpm.soc;
instead of fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
With 500.html there is an error, but with .php it is not, it is logical because I change the config to run php files, but in php errors it doesn't work either.
edit:
domain.com.conf:
server {
listen 80;
server_name www.domain.com;
root /var/www/domain.com/www;
index index.php index.html index.htm;
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
error_page 404 /errors/404.php;
error_page 500 502 503 504 /errors/500.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
500.php:
<!DOCTYPE html>
<html>
<head>
<?php include_once '../meta.php'; ?>
<?=meta500?>
<?php include_once '../header.php'; ?>
<title><?=title500?></title>
</head>
<body>
<?php include_once("../analyticstracking.php") ?>
<?php include_once '../nav.php'; ?>
<?php include_once 'containerError500.php'; ?>
</body>
</html>
This works with 404 page and all other pages.
+3
source to share
No one has answered this question yet
Check out similar questions: