I'm new into nginx and in order to test it I'm migrating from Apache and all I got left is setting up the custom error pages.
These pages are php files (for multi language purposes), I have tried many of the methods from StackOverflow but I cannot figure out how to make it.
Some of them are:
- nginx-php-fpm-custom-error-pages
- nginx-fastcgi-for-php-error-page
- nginx-error-pages-one-location-rule-to-fit-them-all
So far I've created a file /etc/nginx/common/default-error-pages.conf
to include it on the vhosts. This file contains:
error_page 400 /error/400.php;
error_page 401 /error/401.php;
error_page 403 /error/403.php;
error_page 404 /error/404.php;
error_page 500 /error/500.php;
error_page 503 /error/503.php;
location /error/ {
alias /var/www/error/;
autoindex on;
}
location ~ \.php$ {
root /var/www/error/;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
# fastcgi_intercept_errors on;
}
The php files are located in /var/www/error
if I enable the autoindex I'm able to view them from the browser all the files but if I click in any of them the default 404 page is shown.
I have created a symlink of one of those files to a testing site and it gets executed correcly even the css loads as expected.
I've tried nesting the locations and including this config file at the top of the site server
block.
If I change the extension of the php error files to html they are correctly served.
The nginx site is similar to this (file simplified):
server {
listen 4430 ssl http2 default_server;
listen [::]:4430 ssl http2 default_server;
server_name test.local;
root /var/www/html;
index index.php index.html;
# execute php files "helper"
include common/php-files.conf;
fastcgi_hide_header X-Powered-By;
include common/default-error-pages.conf;
location / {
# autoindex on;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
How is supposed to be configured? I've changed it so many times that I don't know what else to try.
Nginx logs files don't reveal any unexpected error/configuration.
Thanks in advance