本番ドメインから始める代わりに、テスト用またはステージング用のドメインでロードバランサーを作成することを推奨します。インフラの構成によっては、モニターやプールを一時的に変更する場合があります。
テストドメインから始めると、本番トラフィックを流す前に、すべてが正しく動作していることを確認できます。
モニターは、ロードバランサーの作成ワークフロー 内、または Monitors タブで作成できます。
-
Load Balancing を開きます。
-
Monitors タブを選びます。
-
Create monitor を選びます。
-
次の情報を追加します。
- Type: ヘルスモニターに使うプロトコルです
- Enterprise 以外のお客様: HTTP、HTTPS、TCP から選びます。
- Enterprise のお客様: HTTP、HTTPS、TCP、UDP ICMP、ICMP Ping、SMTP から選びます。
- Path: ヘルスモニターリクエストを送るエンドポイントのパスです
- Port: ヘルスモニターの宛先ポートです
- Type: ヘルスモニターに使うプロトコルです
-
追加の設定は Advanced health monitor settings を選びます。
- Interval:
- デフォルトを大きくすると、フェイルオーバー時間を改善できますが、エンドポイントの負荷も増える場合があります。
- 最小間隔(秒)は 60(Pro)、15(Business)、10(Enterprise)です。
- Timeout と Retries:
- ヘルスモニターリクエストが Timeout で指定した時間を超え(かつ、その超過回数が指定した Retries 回数を超えた)場合、unhealthy を返します。
- Expected Code(s): 期待する HTTP レスポンスコード。個別に指定する(
200、302)か、範囲で指定します(たとえば2xxと入力すると、200番台のすべてのレスポンスコードが対象になります)。 - Response Body:
- レスポンス本文内の、大文字小文字を区別しない部分文字列を探します。
- 値は比較的静的で、HTML ページの先頭 10 KB 以内にあることを確認してください。
- Simulate Zone:
- ロードバランサーが存在するゾーンと同じゾーンを使うことを推奨します。
- ヘルスモニターリクエストの egress ゾーン設定を変更し、Authenticated Origin Pulls (mTLS)、Argo Smart Routing、Bring your own CA (mTLS)、Dedicated CDN Egress IPs、HTTP/2 to Origin などの機能との互換性を確保します。
- Follow Redirects:
301または302コードを unhealthy として報告する代わりに、ヘルスモニターリクエストは最終エンドポイントまでリダイレクトをたどります。
- Configure Request Header(s):
- エンドポイントが特定の受信ヘッダーを期待している場合に便利です。
- Header:
- ヘルスモニターで送信する HTTP リクエストヘッダーです。デフォルトで Host ヘッダーを設定することを推奨します。User-Agent ヘッダーは上書きできません。このパラメーターは HTTP および HTTPS モニターでのみ有効です。
- Interval:
-
Save を選びます。
ファイアウォールや Web サーバーが、設定したヘルスモニター、または Cloudflare IP アドレス ↗ に関連するリクエストをブロックしたり、レート制限したりしないようにしてください。
各ヘルスモニターの HTTP user-agent は "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/; pool-id: $poolid)" です。$poolid は 関連するプール の先頭 16 文字です。
モニターのプロパティの一覧は、Create Monitor を参照してください。API 認証で困った場合は、Cloudflare API ドキュメント を参照してください。
Required API token permissions
At least one of the following token permissions is required:Load Balancing: Monitors and Pools Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/load_balancers/monitors" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"type": "https",
"description": "Login page monitor",
"method": "GET",
"path": "/health",
"header": {
"Host": [
"example.com"
],
"X-App-ID": [
"abc123"
]
},
"port": 8080,
"timeout": 3,
"retries": 0,
"interval": 90,
"expected_body": "alive",
"expected_codes": "2xx",
"follow_redirects": true,
"allow_insecure": true,
"consecutive_up": 3,
"consecutive_down": 2,
"probe_zone": "example.com"
}'応答には、新しいモニターの完全な定義が含まれます。
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": ":monitor-id",
"created_on": "2021-01-01T05:20:00.12345Z",
"modified_on": "2021-01-01T05:20:00.12345Z",
"type": "https",
"description": "Login page monitor",
"method": "GET",
"path": "/health",
"header": {
"Host": [
"example.com"
],
"X-App-ID": [
"abc123"
]
},
"port": 8080,
"timeout": 3,
"retries": 0,
"interval": 90,
"expected_body": "alive",
"expected_codes": "2xx",
"follow_redirects": true,
"allow_insecure": true,
"consecutive_up": 3,
"consecutive_down": 2,
"probe_zone": "example.com"
}
}ファイアウォールや Web サーバーが、設定したヘルスモニター、または Cloudflare IP アドレス ↗ に関連するリクエストをブロックしたり、レート制限したりしないようにしてください。
各ヘルスモニターの HTTP user-agent は "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/; pool-id: $poolid)" です。$poolid は 関連するプール の先頭 16 文字です。
モニター設定の例
| 項目 | 値 |
|---|---|
| Type | HTTP |
| Path | / |
| Port | 80 |
| Interval | 60 |
| Method | GET |
| Timeout | 5 秒 |
| Retries | 2 |
| Expected Code(s) | 200 |