■はじめに
無料のSSL証明書を設定するにあたり、ドメインを設定しておく必要があります。
CentOSにApatchの設定などが終わっており、http通信ができる前提です。
■手順
SSHでサーバーに接続する(rootユーザーに切り替えてください)
以下のコマンドでファイアーウォール にhttpsが空いていることを確認する。(「services」の部分に「https」があればOK)
firewall-cmd --list-all
以下のコマンドで無料SSLのインストールをする。
yum install certbot python2-certbot-apache
以下のコマンドでドメインに無料SSLを反映する。(以下は「example.com」の例です。)
certbot --apache -d example.com
色々質問されるので、それぞれ回答していく。(以下は私が実施した際の質問です。)
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):
→メールアドレスを入力する。
-------------------------------------------------------------------------------
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:
→Y(SSL証明書発行元にメールアドレスを公開する)
-------------------------------------------------------------------------------
1: Easy - Allow both HTTP and HTTPS access to these sites
2: Secure - Make all requests redirect to secure HTTPS access
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
→2(httpへのアクセスをhttpsにリダイレクトする)
これで、SSLの証明書は設定できたので、以下のコマンドでhttpdを再起動する。
systemctl restart httpd
ブラウザで以下のURLでアクセスしてみてください。(以下はexample.comの場合です。自身のドメインに書き換えてください)
https://example.com
■無料SSLの更新
無料のSSL証明書は3ヶ月で期限が切れます。
いちいち手動で更新させるのはめんどくさいので、自動で更新する方法を記載します。
以下のコマンドを実行し、cronを起動します。
crontab -u root -e
cronに以下を設定します。
0 0 * * * /usr/bin/certbot renew
これで、毎日0時に証明書を確認し、更新できる場合には自動で更新されるようになります。(有効期限の30日前から更新が可能です)