本帖最后由 大神 于 2024-3-18 13:12 编辑
524 错误表明 CloudFlare 能够与源站建立 TCP 连接,但在连接超时之前源站没有回复 HTTP 响应。这意味着 CloudFlare 能够与源服务器建立网络连接,但源服务器响应请求的时间太长。 https://support.cloudflare.com/hc/en-us/articles/200171926-Error-524-A-timeout-occurred 错误524表示Cloudflare成功连接到源web服务器,但在默认的100秒连接超时之前,源没有提供HTTP响应。如果源服务器只是因为有太多的工作要做而花费太长时间,例如,一个大型数据查询,或者因为服务器正在为资源而苦苦挣扎,无法及时返回任何数据,则可能会发生这种情况。 如果源网络服务器在连接已经建立之后确认(ACK)资源请求,但没有及时发送响应,则发生522。 决议 以下是我们建议解决此问题的选项: 实现大型HTTP进程的状态轮询,以避免出现此错误。 请与您的主机提供商联系,以排除源web服务器上的以下常见原因: 源web服务器上的长时间运行的进程。 源web服务器过载。 在源web服务器上记录请求响应时间有助于确定资源缓慢的原因。请联系您的托管提供商或网站管理员,以获得调整日志格式的帮助,或搜索您品牌的web服务器(如Apache或Nginx)的相关日志文档。 企业客户可以使用proxy_read_timeout API端点将524超时时间增加到6000秒。 如果您定期运行耗时超过100秒的HTTP请求(例如,大型数据导出),请将这些进程移到Cloudflare DNS应用程序中未代理的子域(灰色云状)后面。 如果使用Cloudflare Railgun的域出现错误524,请确保lan.timeout设置为高于默认值30秒,然后重新启动Railgun服务。 如果您的过程花费的时间超过 100 秒(1.67 分钟),则 CloudFlare 会抛出错误, This link resolves in PHP 。 修复Cloudflare错误524 本指南将向您展示如何修复Cloudflare的错误524(发生超时) 解释 一个524错误表示Cloudflare能够与源建立TCP连接,但在连接超时之前,源没有用HTTP响应进行回复。 Cloudflare通常会等待来自服务器的HTTP响应100秒。如果您的服务器在这段时间内没有发送响应(<8KB),Cloudflare将关闭连接并提供524错误页面。 此错误通常是由源服务器上的长时间运行的进程引起的,例如PHP应用程序或数据库查询,web服务器在响应请求之前必须等待这些进程。 要解决此问题,您需要在“长时间运行的进程”之前发送一个>8KB的数据。 “长期运行过程”示例 - <?php
- // This script will run for long and will exceed more than 100 seconds and will trigger Cloudflares 524 error.
- sleep(110);
- echo "WOW, you waited me for 110 seconds.";
复制代码
固定样品 - <?php
- // This script will run for long and will exceed more than 100 seconds.
- // To make a fix, you need to send a header or data earlier than your "long-running process".
- // sending a header to fix the error is currently impossible in PHP versions at the moment.
- // sending a data.
- $spacer_size = 8; // increment me until it works
- echo str_pad('', (1024 * $spacer_size), "\n"); // send 8kb of new line to browser (default), just make sure that this new line will not affect your code.
- // if you have output compression, make sure your data will reach >8KB.
- if(ob_get_level()) ob_end_clean(); // end output buffering
- sleep(110);
- echo "WOW, you waited me for 110 seconds.";
复制代码
不工作 选项#1:关闭任何可能缩小文件响应的压缩(apache/nginix中的gzip/delate/br)
选项2:将$spacer_size变量增加1,直到它工作为止
Not working
Option #1: Turn off any compression that may minify the response of the file (gzip/deflate/br in apache/nginx)
Option #2: increment $spacer_size variable by 1 until it works
|