Skip to content

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

カスタムドメインで Pages を指す

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

このチュートリアルでは、オリジンルールと DNS レコードを設定し、カスタムドメイン付きの Pages デプロイを指す方法を説明します。

手順では次の値を例に使います。

訪問者がアクセスする URL mycustomerexample.com/blog/*
ゾーンのドメイン mycustomerexample.com
Cloudflare Pages のサブドメイン myblog.pages.dev
Cloudflare Pages のカスタムドメイン blogmirror.example.com

Pages のカスタムドメインを設定するときは、本番で使う予定のないカスタムドメイン(この例では blogmirror.example.com)を使います。

1. Pages プロジェクトにカスタムドメインを設定する

Pages デプロイへカスタムドメインを追加する手順は次のとおりです。

  1. Cloudflare ダッシュボードで、Workers & Pages ページを開きます。

    Workers & Pages を開く ↗
  2. Pages プロジェクトを選択します。

  3. Custom domains を開きます。

  4. Set up a custom domain を選択します。

  5. blogmirror.example.com を入力し、Continue を選択します。

Pages デプロイにカスタムドメインを追加すると、Cloudflare はそのカスタムドメイン向けの CNAME DNS レコードを自動作成します。

2. Host ヘッダーを書き換え、DNS レコードを上書きするオリジンルールを作成する

mycustomerexample.com ゾーンで、次の設定のオリジンルールを作成します。

受信リクエストが次に一致する場合

フィールド 演算子
URI Path wildcard /blog/*

Expression Editor を使う場合は、次の式を入力します。

(http.request.uri.path wildcard "/blog/*")

オリジンパラメーターを設定する

  • Host header > Rewrite to のあとの値: blogmirror.example.com
  • DNS record > Override to のあとの値: blogmirror.example.com

3. (任意)URL 書き換えを設定する

この例では、訪問者がアクセスする URL は /blog で始まります。一方、Pages デプロイにはこの先頭の URL セグメントはありません。

URL 書き換えを使い、URL パスから /blog セグメントを除きます。

  1. Rules > Overview を開きます。

  2. Create rule > URL Rewrite Rule を選択します。

  3. Rule name にわかりやすいルール名を入力します。

  4. If incoming requests matchWildcard pattern を選択します。

  5. Request URL に次の値を入力します。

    https://<YOUR_HOSTNAME>/blog/*

    この例では、値は https://mycustomerexample.com/blog/* になります。

  6. Then rewrite the path and/or queryPath に、次の値を入力します。

    Target path Rewrite to
    [/] blog/* [/] ${1}
  7. Deploy を選択します。

関連資料

役に立ちましたか?