【问题标题】:500 Server error with Plesk, NGINX, PHP-FPM when removing URL trailing slash删除 URL 尾部斜杠时 Plesk、NGINX、PHP-FPM 出现 500 服务器错误
【发布时间】:2013-09-26 02:02:44
【问题描述】:

我在运行 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 文件并将它们与出现错误的域进行比较。如果可能的话,我宁愿不走那条路。

谢谢!

【问题讨论】:

  • 您是否尝试过从location ~ /$ 中删除$ 符号?
  • 否,但其他域具有相同的代码。我不确定为什么会有所不同。
  • 那么正则表达式 ~ /$ 明确表示 URL 需要以 / 结尾
  • 哇。那行得通!非常感谢!!
  • 好吧,我会用这个创建一个答案,这样你就可以将其标记为已解决

标签: wordpress apache nginx plesk php


【解决方案1】:

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

location / {
    # your rewrites and try_files
}

【讨论】:

  • 完美。非常感谢。
【解决方案2】:

奇怪,没有

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

我的永久链接出现 404 错误。有了它,一切正常。也许它会对某人有所帮助。

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多