【WordPress】Amazon LightsailとCertbotでHTTPS化に挑戦してみた

【WordPress】Amazon LightsailとCertbotでHTTPS化に挑戦してみた

2018-02-033 min read

目次

  1. 概要
  2. 環境
  3. certbotのインストール
  4. 証明書取得
  5. おまけ1--常時ssl
  6. 参考

概要

AWS Lightsail (リンク)とCertbotでHTTPS化に挑戦してみた。 ネットに散らばっている情報を元に"letsencrypt"や"sslなう。"を使ってみたが上手くいかなかった(bitnaminのせいか....)。 改めてCertbotを使ってみたら、すんなりできたので書くことにした。

環境

あらかじめ、WordPressがインストールされている状態で、また以下が設定/構築されている

  • ubuntu16.04
  • ポート80、443
  • DNSが名前解決できる

前準備

sudo apt-get update
sudo apt-get upgradeå
sudo apt-get install git

Certbotのインストール

gitからCertbotを落としてきて10秒くらい待ちます。

cd /usr/local
git clone https://github.com/certbot/certbot
cd certbot

証明書取得

現在のディレクトリでこのコマンドを実行する ./certbot-auto certonly --webroot -w /opt/bitnami/apps/wordpress/htdocs/ -d ドメイン 上手くいくとこのようなメッセージが出る

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/ドメイン名/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/ドメイン名/privkey.pem Your cert will expire on 2018-05-04. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - 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

あとは細かい設定を行い、apacheを再起動します。

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

無事HTTPS化されると思います。

おまけ1 | 常時SSL

httpにアクセスされた際にhttpsへリダイレクトする

sudo vim /opt/bitnami/apache2/conf/bitnami/bitnami.conf

VirtualHostの項目を編集する

<virtualhost _default_:80>
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
</virtualhost>

apache再起動

sudo /opt/bitnami/ctlscript.sh restart apache

参考

https://owani.net/aws/post-625/625/

Tags
javascript(109)
linux(54)
node.js(53)
amazon%20aws(47)
typescript(44)
%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0(36)
%E7%94%BB%E5%83%8F%E5%87%A6%E7%90%86(30)
html5(29)
php(24)
centos(24)
python(22)
%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0(21)
mac(21)
mysql(20)
canvas(19)
opencv(17)
%E9%9B%91%E8%AB%87(16)
docker(16)
wordpress(15)
atcoder(14)
apache(12)
%E6%A9%9F%E6%A2%B0%E5%AD%A6%E7%BF%92(12)
%E3%83%87%E3%83%BC%E3%82%BF%E3%83%99%E3%83%BC%E3%82%B9(12)
amazon%20s3(12)
red%20hat(12)
prisma(12)
ubuntu(11)
github(10)
git(10)
vue.js(10)
%E7%94%BB%E5%83%8F%E5%87%A6%E7%90%86100%E6%9C%AC%E3%83%8E%E3%83%83%E3%82%AF(10)
mariadb(10)
react(9)
aws%20cdk(9)
css3(8)
%E5%8F%AF%E8%A6%96%E5%8C%96(8)
%E5%B0%8F%E3%83%8D%E3%82%BF(8)
nestjs(8)
amazon%20lightsail(7)
next.js(7)
%E3%83%96%E3%83%AD%E3%82%B0(6)
cms(6)
oracle(6)
perl(6)
gitlab(6)
iam(5)
amazon%20ec2(5)
%E8%B3%87%E6%A0%BC%E8%A9%A6%E9%A8%93(5)
aws%20amplify(5)
curl(4)
Author
githubzennqiita
ただの備忘録です。

※外部送信に関する公表事項