AWSが東京(日本)リージョンでも提供を始めた「Amzon Lightsail」は端的に言えばVPSサービスで数クリックでWordPress環境を起動出来たり、LAMP環境も事前に環境が準備されていてVPCとの接続もできるので使い方によっては高度な環境も構築できる優れもの
起動手順は下記ブログを参考にしてください
http://dev.classmethod.jp/referencecat/aws-lightsail/
■「Let’s Encrypt」を導入してみます
Gitがインストールされていなければ
sudo apt-get install git
適当なフォルダで
git clone https://github.com/letsencrypt/letsencrypt cd letsencrypt
SSL証明書を取得するコマンド
./letsencrypt-auto certonly --webroot -w /opt/bitnami/apps/wordpress/htdocs/ -d ドメイン名 Requesting root privileges to run certbot... /home/bitnami/.local/share/letsencrypt/bin/letsencrypt certonly --webroot -w /opt/bitnami/apps/wordpress/htdocs/ -d ドメイン名 Saving debug log to /var/log/letsencrypt/letsencrypt.log Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel):XXXXXXXXXX@XXXX.com ←連絡用メールアドレス ------------------------------------------------------------------------------- Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree in order to register with the ACME server at https://acme-v01.api.letsencrypt.org/directory ------------------------------------------------------------------------------- (A)gree/(C)ancel: a ------------------------------------------------------------------------------- Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about EFF and our work to encrypt the web, protect its users and defend digital rights. ------------------------------------------------------------------------------- (Y)es/(N)o: n Obtaining a new certificate Performing the following challenges: http-01 challenge for ドメイン名 Using the webroot path /opt/bitnami/apps/wordpress/htdocs for all unmatched domains. Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/ドメイン名/fullchain.pem. Your cert will expire on 2017-09-13. To obtain a new or tweaked version of this certificate in the future, simply run letsencrypt-auto again. To non-interactively renew *all* of your certificates, run "letsencrypt-auto renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
取得した証明書のファイルをapache2のssl.confで指定しているファイルへコピー
sudo cp /etc/letsencrypt/live/ドメイン名/fullchain.pem /opt/bitnami/apache2/conf/server.crt sudo cp /etc/letsencrypt/live/ドメイン名/privkey.pem /opt/bitnami/apache2/conf/server.key
apacheの再起動
sudo /opt/bitnami/ctlscript.sh restart apache Unmonitored apache Syntax OK /opt/bitnami/apache2/scripts/ctl.sh : httpd stopped Syntax OK /opt/bitnami/apache2/scripts/ctl.sh : httpd started at port 80 Monitored apache
https://ドメイン名でアクセスして証明書の情報を確認してみる。
ブラウザから確認できる証明書情報が正しく設定されているはず
かなり簡単に無料のSSL証明書が導入できました。
ただ、「Let’s Encrypt」の欠点は証明書の有効期限が約3か月間なので証明書の更新を行わなければいけない。どんな方法がで?
コマンドを実行すればSSL証明書ファイルが更新されるので更新も簡単ですね。ただ私の環境はAWSのLightsailのbitnami環境です。Apache2のssl.confで指定しているSSL証明書(ファイル名)へ取得したSSL証明書をコピーしているので、バッチを作成してcronで毎月1日とかに自動でSSL証明書が更新されるようにしたいと思います。
ちなみに下記のコマンドがSSL証明書更新の際のコマンドで「–dry-run」をオプションに指定すると更新テストができるみたいです。下記はその際のログです。
./certbot-auto renew --force-renewal --dry-run Requesting root privileges to run certbot... /home/bitnami/.local/share/letsencrypt/bin/letsencrypt renew --force-renewal --dry-run Saving debug log to /var/log/letsencrypt/letsencrypt.log ------------------------------------------------------------------------------- Processing /etc/letsencrypt/renewal/ドメイン名.conf ------------------------------------------------------------------------------- Renewing an existing certificate Performing the following challenges: http-01 challenge for ドメイン名 Waiting for verification... Cleaning up challenges ------------------------------------------------------------------------------- new certificate deployed without reload, fullchain is /etc/letsencrypt/live/ドメイン名/fullchain.pem ------------------------------------------------------------------------------- ** DRY RUN: simulating 'certbot renew' close to cert expiry ** (The test certificates below have not been saved.) Congratulations, all renewals succeeded. The following certs have been renewed: /etc/letsencrypt/live/ドメイン名/fullchain.pem (success) ** DRY RUN: simulating 'certbot renew' close to cert expiry ** (The test certificates above have not been saved.) IMPORTANT NOTES: - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal.
自動更新用のバッチ(シェル)ファイルを作成してみます。
#!/bin/sh /home/bitnami/certbot-auto renew --force-renewal sudo cp /etc/letsencrypt/live/ドメイン名/fullchain.pem /opt/bitnami/apache2/conf/server.crt sudo cp /etc/letsencrypt/live/ドメイン名/privkey.pem /opt/bitnami/apache2/conf/server.key sudo /opt/bitnami/ctlscript.sh restart apache
それをご自分の都合に合わせてcronへ登録して動作確認してエラーなく動けばOK!!
追記:SSL証明書の自動更新できました。実行した日付からの証明書期限も2か月後に伸びました。