【问题标题】:Wordpress live site pages return 404 error nginx php-fpmWordpress 实时站点页面返回 404 错误 nginx php-fpm
【发布时间】:2017-02-03 19:02:20
【问题描述】:

我有一个 wordpress 网站,其永久链接设置为帖子名称。除索引外,所有页面均未出现并返回 404。如果我将其设置为普通,那么它们会出现,但缺少许多资源,我不确定为什么。

所以要明确一点,如果永久链接是普通的,它可以工作,但是会有很多错误,因为多个文件(索引除外)上存在 404。 如果 permalink 是 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.

感谢您的帮助!

【问题讨论】:

    标签: php wordpress .htaccess nginx centos7


    【解决方案1】:

    在没有看到实际错误或哪些文件是 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 进行搜索替换。我不止一次忘记了从开发到登台的过程,并且有一个 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;
        }
    

    这是您所拥有的和我运行的配置的混合。让我知道它对你有什么作用。

    【讨论】:

    • 非常感谢! nginx 配置完美运行:) 我错过了。我一直使用 apache,所以 nginx 对我来说是新的!现在只是想弄清楚为什么即使路径正确,整个图像文件夹也会返回 404!谢谢!
    • 嗨,马克,我编辑了我的答案,以便为您提供更接近我个人使用的内容。在我进一步阅读之后,这些教程中缺少一些东西。试试这个,看看它是否有助于 nginx 找到这些图像。干杯!
    • 谢谢!但不幸的是没有:(没有图片。我会弄清楚的,如果我有问题我会再次发布。感谢所有的帮助!
    猜你喜欢
    • 2018-04-03
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2014-04-24
    • 2020-08-08
    • 2013-11-29
    • 2014-07-19
    • 2014-05-31
    相关资源
    最近更新 更多