自己的错误页面与Nginx不起作用



我想创建自己的错误文件。但是我总是看到一个白色网站,上面有"未找到文件"。我已经在PHP位置进行了检查,结果相同。

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name mydomain.com;
    ssl_.........
    root /var/www/html/mydomain.com;
    .....
    error_page 404 /404.php;
    location = /404.php {
        root /var/www/html/mydomain.com/errorpage;
        internal;
    }
    location ^~ /.well-known/acme-challenge/ {
        default_type text/plain;
        root /var/www/letsencrypt;
    }
    location / {
        index index.php;
        try_files $uri $uri/ @rewrite;
    }
    location @rewrite {
        rewrite ^/(site/|contact/)?([^.]+)$ /$1index.php?$2 last;
    }
    location ~ .php$ {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/mydomain.com-php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        proxy_connect_timeout 900;
        proxy_send_timeout 900;
        proxy_read_timeout 900;
        fastcgi_send_timeout 900;
        fastcgi_read_timeout 900;
    }
    .....
}

我找到了许多提示:

fastcgi_intercept_errors on;

和其他行。但是没有机会。

我找到了一个步骤解决方案。

error_page 404 /404.php;
location ~ .php$ {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/mydomain.com-php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        proxy_connect_timeout 900;
        proxy_send_timeout 900;
        proxy_read_timeout 900;
        fastcgi_send_timeout 900;
        fastcgi_read_timeout 900;
        fastcgi_intercept_errors on;
    }

当404.php在主目录中时,这将起作用。当我添加此

location = /404.php {
        root /var/www/html/mydomain.com/errorpage;
        internal;
    }

将找到404.PHP,但它没有进入PHP解析器,并让我下载404.php

您是否知道该如何修复?

最新更新