Let's Encryptを使ったCentOS7のSSL化予忘録です。「設定するドメイン」を設定するドメイン名(例:hoge.jp)に変更してください。
rootユーザーで作業します。間違えていたらごめんなさい。
#Apacheのモジュールインストール
ApacheでSSL化を行うには、mod_sslが必要見たいです。すでにインストールされているかもしれませんが、インストールしましょう。
yum install -y mod_ssl
#ファイアウォール確認
ファイアウォールを確認して、httpsのポートに穴をあけましょう。
#ファイアウォールに穴をあける
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload
#穴が開いたかもう一度確認
firewall-cmd --list-all
ポート番号を指定して、これであけることもできます。
firewall-cmd --zone=public --add-port=443/tcp --permanent
#Let’s Encryptのcertbotをインストール
yum install -y epel-release
yum install -y certbot python2-certbot-apache
#仮想ホストポート80を追加
/etc/httpd/conf/httpd.conf に下記を追記します。
vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin root@設定するドメイン名
DocumentRoot /var/www/html
ServerName 設定するドメイン名
</VirtualHost>
#証明書発行
メールアドレスなどをいろいろ聞かれるので、答えていきましょう。
certbot --apache -d 設定するドメイン
#httpdの再起動
systemctl restart httpd
https://設定したドメイン
にアクセスして、うまくできたかを試してみましょう。
#証明書の更新
certbot renew #残り30日未満の場合のみ更新
certbot renew --force-renew #残り期間に関係なく更新
certbot renew --webroot-path /var/www/html/ --post-hook "systemctl reload httpd" --force-renew #Apache 再起動も実行
#参考にしたサイト
https://knowledge.sakura.ad.jp/10534/
https://dacelo.space/linux/entry-979.html
https://freepc.jp/encrypt
http://www.sassy-blog.com/entry/20180511/1526031971