全球主机交流论坛

标题: 关于 Nginx 404 页面的问题 [打印本页]

作者: juxiangchuan    时间: 2023-2-6 16:56
标题: 关于 Nginx 404 页面的问题
在 Nginx 安装 WordPress 后一切正常。
但是在404页面却遇到了问题。访问 abc.com/asdf 这些不存在的地址显示的是主题的 404 页面,但访问类似 abc.com/asdfg.php  以 ".php" 结尾的不存在地址却显示的是 Nginx 内置的 404 页面。
怎么样才能让以 ".php" 结尾的地址也显示主题的 404 页面呢。
下面是我的配置

  1. upstream php {
  2.         server 127.0.0.1:9000;
  3. }

  4. server {
  5.         server_name .com;
  6.         root /var/www/wordpress;
  7.         index index.php;

  8.         location = /favicon.ico {
  9.                 log_not_found off;
  10.                 access_log off;
  11.         }

  12.         location = /robots.txt {
  13.                 allow all;
  14.                 log_not_found off;
  15.                 access_log off;
  16.         }

  17.         location / {
  18.                 try_files $uri $uri/ /index.php?$args;
  19.         }

  20.         location ~ \.php$ {
  21.                 include fastcgi_params;
  22.                 fastcgi_intercept_errors on;
  23.                 fastcgi_pass php;
  24.                 fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  25.         }

  26.         location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
  27.                 expires max;
  28.                 log_not_found off;
  29.         }
  30. }
复制代码

作者: marcomarco    时间: 2023-2-6 17:05
fastcgi_intercept_errors on 改成off 试一下
作者: poppy    时间: 2023-2-6 17:06
提示: 作者被禁止或删除 内容自动屏蔽
作者: 围观者    时间: 2023-2-6 17:07
本帖最后由 围观者 于 2023-2-6 17:10 编辑


server{
       
        error_page 404 /你主题404页的路径;

}
作者: iks    时间: 2023-2-6 17:15
路由的问题,带 .php 被 nginx 直接处理了,没有被转发到 fcgi,二楼和四楼的方法均可一试
作者: juxiangchuan    时间: 2023-2-6 19:59
本帖最后由 juxiangchuan 于 2023-2-6 20:01 编辑

谢谢各位。2 楼和 4 楼的方法一起用就解决了,单单 2 楼或 4 楼的都无法解决。




欢迎光临 全球主机交流论坛 (https://fd.vvwvv.eu.org/) Powered by Discuz! X3.4