最新的 WordPress 在 Rocky 8 上运行。

将永久链接设置为 Postname 文章,格式为将返回 404。

这是我的 Nginx 配置文件:

server {

    listen       80;
    server_name  xyz.com www.example.com;
    root   /db/docroot/www.example.com;
    index index.php;

    rewrite_log on;
    access_log  /db/logs/host.access.log  main;
    error_log   /db/logs/example.debug.log debug;

location / {
    root /db/docroot/www.example.com;
    index index.php;
    try_files $uri $uri/ /index.php?$args;
 }

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

}

1

  • 您的规范名称和备用名称位于不同的域中。您的规范名称正在使用 apex 记录。您可能应该考虑使用 TLS。但不知道为什么您的 wordpress 无法正常工作。也许如果您在日志中提供了当您尝试解析永久链接时会发生什么的描述,您可能会得到更有用的答案。


    – 


最佳答案
2

可能的原因是:

try_file $uri =404;在您的 PHP 位置块中。您应该将其删除,这样请求就会通过 FastCGI 发送到 PHP-FPM,而不是尝试将其作为静态资源提供。

1

  • 我曾尝试过让它工作并绕过 PHP-FPM。删除它后,它以同样的方式失败。修复方法是移至 Rocky 9,请参阅我的回答。


    – 

经过几个小时的尝试,我安装了一台装有 Rocky 9 的新服务器,将我的 Web 根目录、数据库 mysqldump 和 nginx/PHP-FPM conf 文件 rsync 到新服务器,现在永久链接已正常工作。不确定 Rocky 8 的问题是什么(可能是 PHP 7.4 与 PHP 8 的问题),但 Rocky 9 运行良好。

1

  • 我发布的 nginx 配置在 Rocky 9 上可以正常运行,但删除了“try_file $uri =404;”,正如 Tero 指出的那样,在生产中文件是通过 PHP-FPM 提供的。


    –