WordPress 404不使用主题模板Nginx

时间:2019-12-02 10:50:09

标签: wordpress nginx http-status-code-404

我遇到了这个奇怪的问题。将我们的网站之一移动到LEMP堆栈后,我们注意到,当用户登陆404页面时,服务器显示的是404,而不是WordPress通过主题模板处理404。请参见下面的图1。

Server Response for 404

另外,我的Nginx配置的副本。我不确定这是否是网站404页面未显示的原因。我已删除了有关此问题的一些信息。关于为什么可能会出现这种情况的任何想法?

server {
    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types image/svg+xml text/plain text/html text/xml text/css text/javascript application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript application/x-font-ttf application/vnd.ms-fontobject font/opentype font/ttf font/eot font/otf;

    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name XXXXXXXX.org;
    root /home/forge/XXXXXXXX.org/public;

    /// SSL STUFF HERE (Removed for this question)

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

    location / {
            # This is cool because no php is touched for static content.
            # include the "?$args" part so non-default permalinks doesn't break when using query string
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

    location ~* \.(jpg|jpeg|gif|png)$ {
       expires 60d;
       add_header Cache-Control public;
       try_files $uri $uri/ /$1/$2 =404;
    }

    location ~* \.(pdf|css|html|js|swf)$ {
       expires 20d;
       add_header Cache-Control public;
       try_files $uri $uri/ /$1/$2 =404;
    }
}

在此先感谢您,我一直在寻找解决方案,但是我似乎在Stackoverflow上找不到任何东西。

/编辑/

我设法通过将fastcgi_intercept_errors on;error_page 404 /index.php;添加到对象来弄清楚如何显示404 Nginx页面

location ~ \.php$ {}

我不确定这是向前还是向后?

Updated 404

0 个答案:

没有答案