Wordpress实时站点页面返回404错误nginx php-fpm


Wordpress live site pages return 404 error nginx php-fpm

我有一个wordpress网站的永久链接设置为帖子名称。除了索引之外,所有页面都不会出现并返回404。如果我将其设置为plain,那么它们就会出现,但是许多资源都丢失了,我不确定为什么。

所以只是为了清楚,如果永久链接是普通的,它的工作原理,但有很多错误,因为有一个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' ',我认为你可能在你的nginx配置中缺少try_files。我会看看这个:http://nginxlibrary.com/wordpress-permalinks/

同样,nginx不需要也不想要。htaccess:https://www.nginx.com/resources/wiki/start/topics/examples/likeapache-htaccess/

另外,我会检查以确保您的URL在您的数据库中设置正确。(我想把链接贴出来,但我没有代表)我会使用wp-cli进行搜索替换。我不止一次忘记了从开发阶段转移到登台阶段时要做的事情。:)

希望这些都有帮助!

*编辑以提供更多帮助*

在深入研究了这些教程之后,他们遗漏了一些细节。不用太深入,试着使用更接近下面的内容:

    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;
    }

这是您所拥有的和我运行的配置的混合。