简体   繁体   English

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

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

I'm running into an extremely bizarre error while running a WordPress site. 在运行WordPress网站时,我遇到了一个极其奇怪的错误。

WordPress has permalinks turned on. WordPress已启用永久链接。 The 500 server error occurs when you REMOVE the trailing slash (/) from the URL. 当您从URL中删除结尾的斜杠(/)时,将发生500服务器错误。 For example: www.site.com/about/ -> works fine. 例如:www.site.com/about/->工作正常。 www.site.com/about -> throws a 500 server error. www.site.com/about->抛出500服务器错误。

The error log show the following: 错误日志显示以下内容:

[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 debug log is active, but no errors or warnings are being generated. Wordpress调试日志处于活动状态,但未生成任何错误或警告。

Other points to note: 其他注意事项:

  • The server has multiple domains managed under Plesk 11.5. 该服务器具有在Plesk 11.5下管理的多个域。
  • Only one of the domains suffers from this issue. 只有一个域遭受此问题。

I compared the config vhost.conf files located in /var/www/system/domain/etc/ to another wordpress domain that is not having this issue. 我将/ var / www / system / domain / etc /中的config vhost.conf文件与另一个没有此问题的wordpress域进行了比较。 Everything is identical. 一切都一样。

I also tried removing all of the wordpress files and uploaded a completely fresh copy. 我还尝试删除了所有的wordpress文件,并上传了一个全新的副本。 The problem still occurs, even with a fresh copy of WordPress and no plugins, templates, or anything else. 即使使用WordPress的全新副本并且没有插件,模板或其他任何内容,问题仍然会发生。

One last item that I noticed. 我注意到的最后一项。 My domain specific vhost.conf has the following info: 我的域特定的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;
}

That seems to be looking for anything with a /. 似乎正在寻找带有/的任何内容。 Should I remove the / or add a similar block? 我应该删除/或添加类似的代码块吗? The only reason I haven't tried is because none of the domains suffer from this issue. 我没有尝试过的唯一原因是没有一个域遭受此问题的困扰。 My next course of action would be to download all domain conf files and diff them against the domain with the error. 我的下一个步骤是下载所有域conf文件,并将它们与存在该错误的域进行比较。 I'd rather not go down that path if possible. 如果可能的话,我宁愿不走这条路。

Thanks! 谢谢!

You need to remove the $ from the location block, because this location only matches URL's that end with a / , and since you won't need regex then you can remove ~ too, so the final result is 您需要从位置块中删除$ ,因为此位置仅匹配以/结尾的URL,并且由于不需要正则表达式,因此您也可以删除~ ,因此最终结果是

location / {
    # your rewrites and try_files
}

Strange, without 奇怪,没有

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

I've got 404 error for permalinks. 我的永久链接出现404错误。 And with it everything working. 一切正常。 Maybe it will helps someone. 也许它将帮助某人。

The final, working code for me is as follows: 对我来说,最终的工作代码如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM