Ubuntu の Nginx に対して Let's Encrypt の certbot を設定するには

昔は SSL 証明書は購入することが必要でしたが、最近は Let’s Encrypt が普及したことで無料で https 対応できるようになりました。 ただこの証明書は有効期間が短いため、適切に設定しておかないとすぐに期限切れになってしまいます。 これは、 certbot を使って Ubuntu の Nginx の指定ドメインに対してセットアップするときの忘備録です。 certbot のリポジトリ追加とインストール $ sudo add-apt-repository ppa:certbot/certbot $ sudo apt-get update $ sudo apt-get install python-certbot-nginx 指定したドメインに certbot を設定する $ sudo certbot --nginx -d yourdomain.com 実行すると、下記のとおり出力されます。 途中訊かれるのは http のリクエストを https にリダイレクトするかどうかです。 Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Obtaining a new certificate Performing the following challenges: http-01 challenge for yourdomain.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/yourdomain.com Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/yourdomain.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://yourdomain.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=yourdomain.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/yourdomain.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/yourdomain.com/privkey.pem Your cert will expire on 2019-07-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. 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 外部からの SSL 設定の確認 上記の You should test your configuration at: にある通り、 ブラウザで https://www.ssllabs.com/ssltest/analyze.html?d=_yourdomain.com_ を開いて適切かどうか確認しましょう。 ...

2019年4月8日 · Toshimitsu Takahashi