删除URL尾部斜杠时,Plesk,NGINX,PHP-FPM出现500服务器错误


500 Server error with Plesk, NGINX, PHP-FPM when removing URL trailing slash

我在运行WordPress网站时遇到了一个非常奇怪的错误。

WordPress打开了永久链接。从 URL 中删除尾部斜杠 (/( 时会发生 500 服务器错误。例如:www.site.com/about/->工作正常。www.site.com/about -> 引发 500 服务器错误。

错误日志显示以下内容:

[Tue Sep 24 00:44:58 2013] [warn] [client 75.52.190.1] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Tue Sep 24 00:44:58 2013] [error] [client 75.52.190.1] Premature end of script headers: index.php

WordPress调试日志处于活动状态,但没有生成任何错误或警告。

其他注意事项:

  • 服务器在 Plesk 11.5 下管理多个域。
  • 只有一个域遇到此问题。

我将位于/var/www/system/domain/etc/中的配置 vhost.conf 文件与另一个没有此问题的 wordpress 域进行了比较。一切都是一样的。

我还尝试删除所有wordpress文件并上传一个全新的副本。即使使用WordPress的新副本并且没有插件,模板或其他任何东西,问题仍然存在。

我注意到的最后一项。我的域特定 vhost.conf 包含以下信息:

location ~ /$ {
 index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
 try_files $uri $uri/ /index.php?$args;
}

这似乎正在寻找任何带有/的东西。我应该删除/还是添加类似的块?我没有尝试的唯一原因是因为没有一个域遇到此问题。我的下一个行动方案是下载所有域 conf 文件,并将它们与有错误的域进行比较。如果可能的话,我宁愿不走这条路。

谢谢!

您需要

从位置块中删除$,因为此位置仅与以/结尾的URL匹配,并且由于您不需要正则表达式,因此您也可以删除~,因此最终结果是

location / {
    # your rewrites and try_files
}

奇怪,没有

location ~ /$ {
    try_files $uri /wordpress/index.php?$args;
}

我有永久链接的 404 错误。有了它,一切都在工作。也许它会帮助某人。

对我来说,最终的工作代码如下:

location ~ / {
   index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
   try_files $uri $uri/ /index.php?$args;
}