1回答

0收藏

[求回答] cloudflare页面显示Error code 524错误A timeout occurred

互联网 互联网 29 人阅读 | 1 人回复 | 2024-03-18

What happened?
The origin web server timed out responding to this request.
What can I do?If you're a visitor of this website:
Please try again in a few minutes.
If you're the owner of this website:
The connection to the origin web server was made, but the origin web server timed out before responding. The likely cause is an overloaded background task, database or application, stressing the resources on your web server. To resolve, please work with your hosting provider or web development team to free up resources for your database or overloaded application. Additional troubleshooting information here.

通过Cloudflare的cdn打开页面,页面报错524,提示发生超时。
可以通过在浏览器中访问 ip 来验证服务器已启动,正常。
网页也能打开,正常,就是某个页面打开,会提示524。
我检查了系统日志,apache 日志,没有发现错误。
google了一下,没有找到解决办法。
我知道答案 回答被采纳将会获得1 贡献 已有1人回答
关注下面的标签,发现更多相似文章
"打赏他人,曝光自己,利他利我"
还没有人打赏,支持一下
求知的路上,无穷无尽

回答|共 1 个

大神

发表于 2024-3-18 13:05:20 | 显示全部楼层

本帖最后由 大神 于 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的数据。

“长期运行过程”示例

  1. <?php
  2. // This script will run for long and will exceed more than 100 seconds and will trigger Cloudflares 524 error.

  3. sleep(110);
  4. echo "WOW, you waited me for 110 seconds.";
复制代码

固定样品

  1. <?php
  2. // This script will run for long and will exceed more than 100 seconds.

  3. // To make a fix, you need to send a header or data earlier than your "long-running process".
  4. // sending a header to fix the error is currently impossible in PHP versions at the moment.

  5. // sending a data.
  6. $spacer_size = 8; // increment me until it works
  7. 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.
  8. // if you have output compression, make sure your data will reach >8KB.

  9. if(ob_get_level()) ob_end_clean(); // end output buffering

  10. sleep(110);
  11. 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

还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则