I keep getting a 520 error when trying to load s3 files via my code. It all works fine locally but when I upload the changes to my production server which is behind cloudflare I get a 520 error. Im using IIS 7.5 with asp classic code, here is my test page which is call everytime I want to download a file from s3.
https://www.gbca.org.au/aws_test.asp?fileID=9450&hash=688254C6503507FDDF8CF5D5CD113212&type=pam
It doesnt make sense and cloudflare doesnt provide any error messages.
' #########################################function downloadFile()
Server.ScriptTimeout = 30000set http = Server.CreateObject("Chilkat_9_5_0.Http")http.UnlockComponent("BLUESIHttp_MHoP0vyTTL3e")http.AwsAccessKey = AWS_ACCESS_KEYhttp.AwsSecretKey = AWS_SECRETif bucketType = "not-secure" thenhttp.AwsEndpoint = "s3.ap-southeast-1.amazonaws.com"http.AwsRegion = "ap-southeast-1"bucketLocale = AWS_BUCKET_ASIAelsehttp.AwsEndpoint = "s3.ap-southeast-2.amazonaws.com"http.AwsRegion = "ap-southeast-2"bucketLocale = AWS_BUCKET_SECUREend ifs3FileBytes = http.S3_DownloadBytes(bucketLocale, objectName)If (http.LastMethodSuccess <> 1) ThenResponse.Write "<pre>" & Server.HTMLEncode(http.LastErrorText) & "</pre>"Response.EndEnd 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.ClearResponse.AddHeader "Pragma", "no-cache"Response.AddHeader "Content-Disposition", "attachment; filename=""" & filename & """"Response.AddHeader "Content-Length", ubound(s3FileBytes)Response.AddHeader "Connect", "close"Response.ContentType = filetypeResponse.BinaryWrite s3FileBytesset AWS = nothing'-- log the file access'SQLLine = "INSERT INTO download_history (fileID, who, etc) VALUES (" & fileID & ")"'DBCC.execute(SQLLine)
end function
https://www.gbca.org.au/aws_test.asp?fileID=9450&hash=688254C6503507FDDF8CF5D5CD113212&type=pam
Best Answer
Error 520 is essentially a catch-all response when something unexpected happens or when the origin server incorrectly interprets or does not tolerate a request due to a protocol violation or an empty response.
Besides reviewing your server logs, I recommend contacting Cloudflare support to review logs on their end as well. Unless you're on Enterprise Plan and explicitly requested to enable 100% logs, keep in mind they only keep 1% anonymized sampled logs for a limited time, so the logs might not be available if you contact them too late.
I've seen cases where nginx error upstream prematurely closed connection while reading response header from upstream
was observed, upstream in this case means the origin server. This indicates that the origin server or the path along which it travelled was having issues during this period which caused Cloudflare to generate those 520 errors. Correlating the timestamp with your server's logs will give you better picture as to what the root cause could possibly be.