【问题标题】:Nginx custom 404 page with php not working带有php的Nginx自定义404页面不起作用
【发布时间】: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


【解决方案1】:

将配置文件error_page 404 /404.php; 中的行重写为error_page 404 /404;

检查您的 nginx.conf 文件是否包含您描述的站点的文件 conf

不要忘记在更改后通过命令systemctl reload nginx重新加载nginx,也可以在reload之前通过命令nginx -t检查语法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-06
    • 2010-11-04
    • 2011-12-23
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多