Wordpress 实时网站页面 return 404 错误 nginx php-fpm

Wordpress live site pages return 404 error nginx php-fpm

我有一个永久链接设置为 post 名称的 wordpress 网站。除索引外,所有页面均未出现并且 return 出现 404。如果我将它设置为普通,它们就会出现,但是很多资源都丢失了,我不确定为什么。

所以要清楚一点,如果永久链接是普通的,它可以工作,但随后会出现很多错误,因为多个文件(索引除外)上有 404。 如果固定链接是 postname 那么整个页面都是 404.

这是我的 htaccess 文件、我的 nginx 配置和我的 php-fpm 配置。 谁能看出问题所在?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

NGINX 配置

server {
    listen 80;
    server_name www.example.com example.com;
    root /var/www/example;
    return 301 https://$server_name$request_uri;
}   

server {
    listen       443 ssl;
    server_name  www.example.com example.com;
    root   /var/www/example;
    index index.php;
    ssl_certificate /etc/nginx/ssl/example.com/example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com/example.com.key;

    access_log  /var/log/nginx/example.log main;
    error_log  /var/log/nginx/example_error.log;

    location / {
        root   /var/www/example;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}

PHP-FPM

[example]
listen = 127.0.0.1:9001
listen.allowed_clients = 127.0.0.1
user = nginx
group = nginx
...and some more I don't think is relevant but I can supply if asked for.

感谢大家的帮助!

没有看到实际错误或哪些文件是 404'ing,我认为您的 nginx 配置中可能缺少 try_files。我会检查这个: http://nginxlibrary.com/wordpress-permalinks/

此外,nginx 不需要或不需要 .htaccess: https://www.nginx.com/resources/wiki/start/topics/examples/likeapache-htaccess/

此外,我会检查以确保您的 URL 在您的数据库中设置正确。 (我会 post link 但我没有代表) 我会使用 wp-cli 进行搜索替换。我不止一次忘记这样做,从开发转移到暂存并且有一个 wtf 时刻。 :)

希望这对您有所帮助!

* 编辑以提供更多帮助 *

在深入研究了这些教程之后,他们遗漏了一些更好的要点。不用太深入,尝试使用更接近于此的东西:

    listen       443 ssl;        
    root /var/www/example;
    index index.php index.html index.htm;

    server_name www.example.com example.com;

    ssl_certificate /etc/nginx/ssl/example.com/example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com/example.com.key;

    access_log  /var/log/nginx/example.log main;
    error_log  /var/log/nginx/example_error.log;

    location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
               try_files $uri =404;
               fastcgi_split_path_info ^(.+\.php)(/.+)$;
               fastcgi_pass   127.0.0.1:9001;
               fastcgi_index index.php;
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
               include fastcgi_params;
    }

这是您的配置和我的配置的混合 运行。让我知道它对你有何帮助。