Error 520, 521, 522, 523, 524 บน Cloudflare แก้ไขอย่างไร

เมื่อใช้ Cloudflare แล้วเจอ Error 5xx บนหน้าเว็บ หลายคนสับสน บทความนี้อธิบายความหมายของแต่ละวิธีแก้ไขอย่างตรงจุด

Error 520 — Web Server ส่งคืน Response ผิดปกติ

Error 520 เกิดขึ้นเมื่อ Origin Server ส่งคืน Response ที่ Cloudflare ไม่รู้จัก เช่น HTTP Response ที่ไม่ถูกต้อง หรือ Connection ที่แปลก

วิธีแก้ไข:

  • ตรวจสอบ Error Log บน Web Server (Nginx/Apache) ว่ามีข้อผิดพลาดอะไรหรือไม่
  • ตรวจสอบว่า Server ส่งคืน HTTP Response ที่ถูกต้อง ไม่ใช่ Empty Response
  • ตรวจสอบ Firewall บน Server ว่าไม่ได้ Block Cloudflare IPs
  • Restart Web Server เพื่อรีเซ็ต Connection

Error 521 — Web Server ไม่ตอบสนอง

Error 521 เกิดสาเหตุจาก Cloudflare พยายามเชื่อมต่อ Port 80 หรือ 443 บน Origin Server แต่เชื่อมต่อไม่สำเร็จ

สาเหตุที่พบบ่อย:

  • Web Server (เช่น Nginx หรือ Apache) หยุดทำงาน หรือ Crash
  • Firewall บน Server Block Port 80 หรือ 443
  • Server Overload จนไม่สามารถรับ Connection ใหม่
# ตรวจสอบสถานะ Web Server
systemctl status nginx
systemctl status apache2

# ตรวจสอบ Port
netstat -tlnp | grep ':80\|:443'

# ตรวจสอบ Firewall
iptables -L -n | grep '80\|443'
ufw status

Error 522 — Connection Timed Out

Error 522 เกิดสาเหตุจากการเชื่อมต่อของ Cloudflare ไปยัง Origin Server ใช้เวลานานเกินไปจนหมด Timeout (15 วินาที)

  • ตรวจสอบว่า Server คือ Load สูงเกินไปหรือไม่
  • ตรวจสอบ CPU และ RAM และ Disk I/O ด้วย top, htop
  • ตรวจสอบว่า Web Application จัดการ Database Query ช้าติทะค์หรือไม่
  • หากสาเหตุเป็น Script ที่ช้า ให้เพิ่ม Proxy Read Timeout ใน Cloudflare

Error 523 — Origin Unreachable

Error 523 แสดงว่า Cloudflare ไม่สามารถเข้าถึง Origin Server ได้เลย มักเกิดจาก IP Address ของ Origin ผิดพลาด หรือ Server ไม่ทำงาน

  • ตรวจสอบว่า DNS A Record ชีควาไปยัง IP ของ Server ถูกต้อง
  • SSH เข้าไปตรวจสอบว่า Server ยังทำงานอยู่
  • ตรวจสอบ Network Interface ว่าทำงานอยู่

Error 524 — Timeout Occurred

Error 524 คล้ายกับ 522 แต่เกิดหลังจาก Cloudflare เชื่อมต่อสำเร็จแล้ว แต่รอ 100 วินาทีโดยไม่ได้รับ Response เลย

  • เหมาะสำหรับ Long-running Operations เช่น Video Processing, File Upload ขนาดใหญ่
  • แก้ไขโดยใช้ Cloudflare Workers หรือเปลี่ยนไปใช้การทำงานแบบ Asynchronous
  • ตั้งค่า Proxy Read Timeout ใหสูงขึ้นในแผน Enterprise

สรุปตาราง Error Codes

Error Code สาเหตุหลัก วิธีแก้ไข
520 Web Server ตอบสนองผิดปกติ ตรวจสอบ Error Log บน Server
521 Web Server ไม่ตอบสนอง (Port Closed) Restart Web Server, เช็ค Firewall
522 Connection Timeout (15 วิ) Server Load สูง หรือ Script ช้า
523 Origin Unreachable DNS A Record ผิด, Server Down
524 Response Timeout (100 วิ) Long-running Task, ใช้ Async

หากคุณใช้งาน VPS หรือ Cloud Hosting และพบ Error เหล่านี้ เริ่มตรวจสอบจาก Server Side ก่อนเสมอ เพราะส่วนใหญ่แล้วสาเหตุมาจากเซิร์ฟเวอร์ไม่ใช่จาก Cloudflare