Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

キャッシュをカスタマイズする

最終更新 Markdown で表示Agent セットアップ

オリジンウェブサーバーの設定と Cloudflare の Cache Rules を組み合わせる例は、次のとおりです。

オリジンウェブサーバーに静的コンテンツ用ディレクトリを作る

たとえば、オリジンウェブサーバーに /static/ サブディレクトリを作り、次の式に一致する Cache Everything の Cache Rule を作成します。

  • Expression Builder を使う場合: Hostname contains "example.com" AND URI Path starts with "/static"
  • Expression Editor を使う場合: (http.host contains "example.com" and starts_with(http.request.uri.path, "/static"))

静的ページに固有のファイル拡張子を付ける

たとえば、オリジンウェブサーバーのリソースに .shtml 拡張子を付け、次の式に一致する Cache Everything の Cache Rule を作成します。

  • Expression Builder を使う場合: Hostname contains "example.com" AND URI Path ends with ".shtml"
  • Expression Editor を使う場合: (http.host contains "example.com" and ends_with(http.request.uri.path, ".shtml"))

リソースの URL にクエリ文字列を付けて静的コンテンツとみなす

たとえば、オリジンウェブサーバーのリソースに static=true クエリ文字列を付け、次の式に一致する Cache Everything の Cache Rule を作成します。

  • Expression Builder を使う場合: Hostname contains "example.com" AND URI Query String contains "static=true"
  • Expression Editor を使う場合: (http.host contains "example.com" and http.request.uri.query contains "static=true")

Cache Everything の Cache Rule に一致するリソースでも、オリジンウェブサーバーが max-age=0privateno-cache の Cache-Control ヘッダー、またはすでに期限切れの日付の Expires ヘッダーを送るとキャッシュされません。オリジンウェブサーバーの Cache-Control ヘッダーも上書きするには、Cache Everything の Cache Rule に Edge Cache TTL 設定を含めます。

役に立ちましたか?