LoginSignup
3
3

More than 5 years have passed since last update.

Octopress + S3 + CloudFront + 独自ドメインで運用しているブログをhttps転送運用にした

Posted at

概要 と 動機

Octopress + S3 + CloudFront + 独自ドメインで運用しているブログを

  • https対応
  • http → httpsに転送

対応させてgoogle検索上位にきてほしい。

&

httpsじゃないページなんてありえないっすよー。とか真面目に営業するのに言い訳ができる。

コスト的にはAWSは特に変わらず(無料)、純粋にSSL証明書のお値段のみ。

やったこと と ハマりどころ

Octopress + S3 + CloudFront + 独自ドメイン までは運用してる状況においてやること

  1. 証明書を取得
  2. 証明書をAWSにアップロード
  3. CDNに設定し、http → https 自動転送ONにする

1. 証明書を取得

SSLストア 【RapidSSL 1,620円 Verisign 60,000円 GeoTrust 12,780円】で、COMODO PositiveSSLを1年1200円で購入。

メールで認証があって、最終的には中間証明書3つと自分の証明書が送られてくる。

アップロード用に中間証明書の結合

中間証明書で指定できるのが1ファイルのみのようなので結合してしまう。本来はopensslコマンドでやるべきらしいが、単なるファイルの結合なのでcatでやってしまう。

cat COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt > COMODO-bundle.crt

秘密鍵をdecryptしておくこと

まぁこのあたりはApache使うときにするのと同じ。

openssl rsa -in secret_key.pem -out secret_key.pem.decrypt

2. 証明書をAWSにアップロード

  • file:// で指定すること。
  • pathオプションで /croudfront/.+/ な正規表現にマッチさせないと後ででてこない
  • アップロードはroleいるので注意
$ aws iam upload-server-certificate \
  --server-certificate-name certificate_object_name \
  --certificate-body file:///Users/pharaohkj/octopress_phalanxware_com.crt \
  --private-key file:///Users/pharaohkj/secret_key.pem.decrypt \
  --certificate-chain file:///Users/pharaohkj/COMODO-bundle.crt \
  --path /cloudfront/path/

3. http → https

CloudFrontのconsoleに入って、対象のDistributionを選んで

Generalタブ > Editボタン

SSL CertificateCustom SSL Certificate (example.com) に。(さっきの --server-certificate-name がでるはず)

Originsタブ > 対象のドメインとパスを選ぶ > Editボタン

Origin Protocol Policy を HTTP Only なのを確認。よくわからない。おそらくCDNとS3間の接続プロトコル指定ということだと思うんだが・・・。 Match Viewer を選んだら私はcacheにヒットしない、というような( CloudFront attempted to establish a connection with the origin, but either the attempt failed or the origin closed the connection. )エラーになった。

Behaviorタブ > 対象を選んで > Editボタン

Viewer Protocol Policy を Redirect HTTP to HTTPS に変更。httpsのみとかってのは最初からいくならこれでもいいかもね。

課題

Amazonプラグインとかが、リンクや画像の埋め込みを http で作っちゃったりして、イマイチ。

3
3
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
3
3