Cloudflare: Error 522 - Connection timed out
CloudflareがオリジンサーバーへのTCP接続に失敗した際のエラー原因と解決策
概要
Cloudflareがオリジンサーバーへの接続を確立できない場合に発生するエラーです。
エラーメッセージ
``` Error 522: Connection timed out ```
原因
- オリジンサーバーがダウン: Webサーバーが停止
- ファイアウォールのブロック: CloudflareのIPがブロック
- ポートが閉じている: 80/443が開いていない
- オリジンの過負荷: リクエストを処理できない
- TCP接続の制限: keep-aliveの設定ミス
解決策
1. CloudflareのIPを許可
```bash
CloudflareのIPレンジを取得
curl https://www.cloudflare.com/ips-v4 curl https://www.cloudflare.com/ips-v6
iptables で許可
iptables -A INPUT -p tcp -s 173.245.48.0/20 –dport 443 -j ACCEPT
他のIPレンジも同様に追加
```
2. オリジンサーバーの状態確認
```bash
直接接続テスト
curl -v –resolve example.com:443:YOUR_ORIGIN_IP https://example.com
ポート確認
nc -zv YOUR_ORIGIN_IP 443
サービス状態
systemctl status nginx ```
3. Cloudflareのタイムアウト設定
``` Cloudflare Dashboard: Speed > Optimization > Network
- Enable Argo Smart Routing
- Increase Origin Connection Timeout (Enterprise) ```
4. オリジンのKeep-Alive設定
```nginx
nginx.conf
http { keepalive_timeout 300; keepalive_requests 1000; } ```
5. 一時的にCloudflareをバイパス
``` Cloudflare Dashboard: DNS > Records 該当レコードのProxy statusをDNS onlyに変更(オレンジ雲→灰色雲) ```
よくある間違い
- CloudflareのIPレンジを定期的に更新しない
- オリジンのSSL証明書が無効
- Cloudflareの背後に別のプロキシ
関連エラー
関連エラー
この記事は役に立ちましたか?