0
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?

More than 3 years have passed since last update.

Google Cloud Storage + Google Cloud CDNの環境を作ってみる

Posted at

前説

  • Google Cloud Storage には組み込みキャッシュがある。癖はあるが、通常は組み込みキャシュに任せている。
  • ただし、キャッシュ可能な最大ファイルサイズが10MBなので、それ以上のファイルはキャッシュしてくれない
  • 10MB以上のファイルを配信したい場合は、Google Cloud CDNを使うのが良いようだ

前提条件

Google Cloud Storage

  • Cloud Storage > バケットを作成
    • バケット名 : 任意
    • ロケーション タイプ : Region
    • ロケーション : 任意 (東京にした)
    • ストレージ クラス : Standard
    • オブジェクトへのアクセスを制御する方法 : きめ細かい管理
    • 以上で作成
  • 作成したバケットの > 権限 > 権限追加
  • allUser で ロールに storage レガシー バケット読み取り を追加
  • 一般公開バケットになる
  • テスト用のファイル(test.png)をアップロード

Google Cloud CDN

  • ネットワークサービス > Cloud Load balancing > ロードバランサを作成
  • HTTP(S) 負荷分散 を選択
  • インターネットから VM またはサーバレスサービスへ を選択し続行
    • バックエンドバケット名 : 任意
    • Cloud Storageバケット : 先ほど作成したバケットを選択
    • Cloud CDNを有効にする を選択
    • 静的コンテンツをキャッシュする を選択
    • 高度な構成を表示して、カスタム レスポンス ヘッダー追加
      • ヘッダー名 : Cache-Status
      • ヘッダーの値 : {cdn_cache_status}
    • 以上で作成
  • 作成した ロードバランサを選択し、IPを確認

動作確認

  • curlで確認
$ curl -v -o/dev/null http://<ロードバランサのIP>/test.png
HTTP/1.1 200 OK
...
< Cache-Control: public,max-age=3600
< Cache-Status: miss

$ curl -v -o/dev/null http://<ロードバランサのIP>/test.png
HTTP/1.1 200 OK
...
< Cache-Control: public,max-age=3600
< Cache-Status: hit

キャッシュされている

以降の手順

Cloud CDNだけではhttps配信できないので
外部 IP アドレスの予約、SSL 証明書リソース作成等必要だが、今回はここまで。

0
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
0
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?