【发布时间】:2018-07-23 11:19:15
【问题描述】:
我正在尝试使用自定义 404.php 页面来处理 404 错误,而不是使用默认的 nginx 错误页面,但到目前为止我尝试的所有方法都不起作用。我可以毫无问题地提供自定义 404.html 页面,但不能让它为 php 工作。以下是我在默认配置中尝试的,但没有成功。
error_page 404 /404.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_intercept_errors on;
}
我也试过
error_page 404 = /404.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_intercept_errors on;
}
我正在使用 nginx/1.10.3 (Ubuntu)
【问题讨论】:
-
你有静态页面404.php吗?
-
@IgorCova 我的根目录中有一个 404.php 页面。 /var/www/html/404.php
-
在
include snippets/fastcgi-php.conf;之后添加行root /var/www/html;和internal; -
@IgorCova 我刚试过,不幸的是它仍然显示默认的 nginx 404。
-
你是否重新加载了 nginx?
标签: nginx