2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cloudflare R2のオブジェクトを直接インターネットに公開してみる(カスタムドメイン使用)

Last updated at Posted at 2024-06-29

概要

R2のオブジェクト(htmlファイル)を直接インターネットに公開し、ブラウザからアクセスしてみる。
前回はr2.devのドメインを使った公開を行った。今回はカスタムドメインを使用して公開してみる。

前回↓

前提

Cloudflareに DNSで管理されているドメイン、またはサブドメインがあること。筆者は下記の対応でDNSをRoute53からCloudflareDNSに移管し、R2のカスタムドメインはpublic.www.miriwo.workを用いることにする。(実はwww.miriwo.workを使いたかったけどCloudflare Works&Pagesで使ってて、)

下記のindex.htmlをアップロードして公開してみる。

index.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <h1>Hello Cloudflare R2(Custom Domain)</h1>
</body>
</html>

方法

  1. 公開用バケット(筆者の場合バケット名は「public-custom-domain」)を追加

    • 位置情報: 自動
    • デフォルトのストレージ クラス: Standard
  2. バケットの詳細画面で「設定タブ」を開き下部の「カスタムドメイン」の「ドメインに接続」をクリック

    CleanShot 2024-06-29 at 01.17.17@2x.png

    CleanShot 2024-06-29 at 01.18.25@2x.png

  3. カスタムドメインを入力して「続行」をクリック

    CleanShot 2024-06-29 at 13.19.46.png

  4. CNAMEレコードを追加する案内が出るので「ドメインに接続」をクリック

    CleanShot 2024-06-29 at 13.20.22.png

  5. ドラックアンドドロップでindex.htmlをバケットにアップロード

  6. アップロードしたオブジェクトの詳細を開き、URLをコピー

    CleanShot 2024-06-29 at 13.22.21.png

  7. コピーしたURLをブラウザに貼り付けて、下記のようなページが表示されれば完了

    CleanShot 2024-06-29 at 13.23.30.png

  8. デフォルトで7日後にアップロードを中止?するルールが付与されている模様なので不要なら編集したりしたほうがいい

    CleanShot 2024-06-29 at 13.27.43.png

  9. 本体験後には当該のバケットへのアクセス許可を無効に設定しておいた。

参考文献

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?