Php nginx上的自定义500错误页不工作

Php nginx上的自定义500错误页不工作,php,nginx,Php,Nginx,我想在nginx中添加我自己的错误页面。在服务器配置中,我有: error_page 404 /errors/404/index.php; error_page 500 502 503 504 /errors/500/index.php; location /errors/ { root /var/www/<host>/public_html/; internal; location ~ \.php$ { include snipp

我想在nginx中添加我自己的错误页面。在服务器配置中,我有:

error_page 404 /errors/404/index.php;
error_page 500 502 503 504 /errors/500/index.php;

location /errors/ {
    root /var/www/<host>/public_html/;
    internal;
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_split_path_info ^(.+/\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }
}

location / {
    try_files $uri $uri/ =404;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    fastcgi_split_path_info ^(.+/\.php)(/.+)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
}
error\u第404页/errors/404/index.php;
error_第500页502 503 504/errors/500/index.php;
位置/错误/{
root/var/www//public_html/;
内部的;
位置~\.php${
包括snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi\u split\u path\u info^(.+/\.php)(/.+)$;
fastcgi_参数路径_信息$fastcgi_路径_信息;
fastcgi\参数脚本\文件名$document\根$fastcgi\脚本\名称;
fastcgi_截获_错误开启;
}
}
地点/{
try_files$uri$uri/=404;
}
位置~\.php${
包括snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi\u split\u path\u info^(.+/\.php)(/.+)$;
fastcgi_参数路径_信息$fastcgi_路径_信息;
fastcgi\参数脚本\文件名$document\根$fastcgi\脚本\名称;
fastcgi_截获_错误开启;
}
404错误正确显示。虽然我故意在php文件中犯了一个错误,导致服务器上出现500个错误,但错误仍然存在:


有人知道为什么不显示给定页面吗?nginx日志中没有错误。谢谢。

Regex匹配位置比前缀位置具有更高的优先级,因此
/errors/xxx/index.php
uri将使用
location~\.php${…}
而不是
location/errors/{…}
捕获。要使
location/errors/{…}
优先于
location~\.php${…}
使用
^
位置修饰符:
location^~/errors/{…}