【问题标题】:520 Error everytime I run my code behind Cloudflare每次我在 Cloudflare 后面运行代码时都会出现 520 错误
【发布时间】:2019-07-10 13:59:18
【问题描述】:

尝试通过我的代码加载 s3 文件时,我不断收到 520 错误。在本地一切正常,但是当我将更改上传到 cloudflare 后面的生产服务器时,我收到 520 错误。我使用带有 asp 经典代码的 IIS 7.5,这是我的测试页面,每次我想从 s3 下载文件时都会调用它。

https://www.gbca.org.au/aws_test.asp?fileID=9450&hash=688254C6503507FDDF8CF5D5CD113212&type=pam

这没有意义,cloudflare 不提供任何错误消息。

' ######################################## 函数下载文件()

Server.ScriptTimeout = 30000

set http = Server.CreateObject("Chilkat_9_5_0.Http")
http.UnlockComponent("BLUESIHttp_MHoP0vyTTL3e")
http.AwsAccessKey = AWS_ACCESS_KEY
http.AwsSecretKey = AWS_SECRET

if bucketType = "not-secure" then
    http.AwsEndpoint = "s3.ap-southeast-1.amazonaws.com"
    http.AwsRegion = "ap-southeast-1"
    bucketLocale = AWS_BUCKET_ASIA
else
    http.AwsEndpoint = "s3.ap-southeast-2.amazonaws.com"
    http.AwsRegion = "ap-southeast-2"
    bucketLocale = AWS_BUCKET_SECURE
end if

s3FileBytes = http.S3_DownloadBytes(bucketLocale, objectName)

If (http.LastMethodSuccess <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode(http.LastErrorText) & "</pre>"
    Response.End
End If

'response.write("AWS_BUCKET_ASIA: " & AWS_BUCKET_ASIA & "<br />")
'response.write("objectName: " & objectName& "<br />")
'response.write("s3FileBytes: " & ubound(s3FileBytes) & "<br />")
''response.write("s3FileBytes: " & filetype & "<br />")
''response.end()

Response.Clear
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Content-Disposition", "attachment; filename=""" & filename & """"
Response.AddHeader "Content-Length", ubound(s3FileBytes)
Response.AddHeader "Connect", "close"
Response.ContentType = filetype
Response.BinaryWrite s3FileBytes

set AWS = nothing

'-- log the file access
'SQLLine = "INSERT INTO download_history (fileID, who, etc) VALUES (" & fileID & ")"
'DBCC.execute(SQLLine)

结束函数

https://www.gbca.org.au/aws_test.asp?fileID=9450&hash=688254C6503507FDDF8CF5D5CD113212&type=pam

【问题讨论】:

标签: amazon-web-services amazon-s3 cloudflare


【解决方案1】:

Error 520 本质上是一个包罗万象的响应,当意外发生或当源服务器由于协议违规或空响应而错误地解释或不容忍请求时。

除了查看您的服务器日志之外,我还建议您联系 Cloudflare 支持以查看他们的日志。除非您使用的是企业计划并明确要求启用 100% 日志,否则请记住,他们只会在有限的时间内保留 1% 的匿名抽样日志,因此如果您联系他们太晚,这些日志可能无法使用。

我见过观察到 nginx 错误upstream prematurely closed connection while reading response header from upstream 的情况,在这种情况下,上游是指原始服务器。这表明原始服务器或它所经过的路径在此期间出现问题,导致 Cloudflare 生成这些 520 错误。将时间戳与您的服务器日志相关联可以让您更好地了解根本原因可能是什么。

【讨论】:

  • 感谢您的回复 Faiz。我发现问题在于内容长度标头。我从我的代码中删除了它,现在文件下载并且没有 520 错误。
猜你喜欢
  • 2020-05-18
  • 2023-01-13
  • 2022-11-07
  • 1970-01-01
  • 1970-01-01
  • 2019-11-24
  • 1970-01-01
  • 1970-01-01
  • 2012-07-31
相关资源
最近更新 更多