Cloudflare Tunnelが不安定なときにチェックすること

Table of Contents

症状

Cloudflare tunnelを使ってセルフホストしているWebサイト(このサイト)が不安定になりました。

具体的には、502 Bad Gateway, 1033 Cloudflare Tunnel Error, 530 The origin has been unregistered from Argo Tunnel のステータスでサイトが落ちます。数分したらまた繋がるようにはなります。

原因

トンネルエラーなので Cloudflare tunnel の通信を受ける Cloudflared のログを見てみます。

Jun 26 21:34:41 cloudflare-tunnel-wordpress cloudflared[179]: 2025-06-26T21:34:41Z ERR Failed to serve quic connection error="failed to accept QUIC stream: timeout: no recent network activity" connIndex=1 event=0 ip=198.41.200.23
Jun 26 21:34:41 cloudflare-tunnel-wordpress cloudflared[179]: 2025-06-26T21:34:41Z ERR Serve tunnel error error="failed to accept QUIC stream: timeout: no recent network activity" connIndex=1 event=0 ip=198.41.200.23

QUICプロトコルで繋がっているトンネルの接続が定期的に切れているらしい。QUICは、TCPと同様の信頼性がありつつ下位層にUDPを使っているいい感じのプロトコルらしいです(適当)

QUICプロトコルの通信において、一定時間通信がないとルーターが勝手にNATテーブルを削除してしまうのが原因のよう。(ソースはChatGPT)

対策

IPv6で通信すればNATは関係なくなるはずですが、何かの拍子でv4で繋がってまた不安定になられても困るのでQUICを使わないようにしました。

Cloudflared の起動オプションで、QUICをやめてHTTP/2を指定します(–protocol http2)

sudo nano /etc/systemd/system/cloudflared.service
[Unit]
Description=cloudflared
After=network-online.target
Wants=network-online.target

[Service]
TimeoutStartSec=0
Type=notify
ExecStart=/usr/bin/cloudflared tunnel --no-autoupdate --protocol http2 run --token <your token>
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl restart cloudflared

おすすめ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Table of Contents

Index