完全に自分用メモ。普通はnginxとか使うよねw
Lighttpdとcertbotインストール
sudo apt-get install lighttpd certbot
certbotを設定
Lighttpdが80番ポートを使って動いているはずなので、 --webroot
オプションを使うのがラク。
sudo certbot certonly --webroot
Input the webroot for <ドメイン名>: (Enter 'c' to cancel):
みたいな質問には /var/www/html
と答えておけば
Waiting for verification...
Cleaning up challenges
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 2020-02-02. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot 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
無事に証明書がもらえる。
lighttpdのSSL有効化
cat /etc/letsencrypt/live/<ドメイン名>/cert.pem /etc/letsencrypt/live/<ドメイン名>/privkey.pem | sudo tee /etc/lighttpd/server.pem
sudo lighttpd-enable-mod ssl
sudo /etc/init.d/lighttpd restart
これで、 /var/www/html
配下のコンテンツがSSLでも配信できるようになっているはず
常時SSL化
https://redmine.lighttpd.net/projects/1/wiki/HowToRedirectHttpToHttps に書いてあるまんまなんだけど、
$HTTP["scheme"] == "http" { url.redirect = ("" => "https://${url.authority}${url.path}${qsa}") }
を /etc/lighttpd/conf-enabled/10-ssl.conf
に追記して /etc/init.d/lighttpd restart
するだけ。
手元から
$ curl -v http://<ドメイン名>/
して、301リダイレクトでhttpsが付いているURL指定になっていることを確認して、完了。