1
2

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 5 years have passed since last update.

certbot+lighttpdで常時SSLな静的サイトをささっと作る

Last updated at Posted at 2019-11-04

完全に自分用メモ。普通は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でも配信できるようになっているはず

image.png

常時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指定になっていることを確認して、完了。

1
2
1

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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?