Access: 1946180
p-lux.net Ver.10.00 by Ryogo
CentOS 7 に sslモジュールやLet's Encrypt等をインストールしてみた覚書
テストサーバでhttpsが使いたくなったのでその覚書


バージョンはこんな感じ。

# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 16 2020 16:18:20


■sslモジュールのインストール

#yum -y install mod_ssl
#systemctl restart httpd


■certbotのインストール

#yum install --enablerepo=epel certbot


■証明書の発行

#certbot certonly --webroot -w /var/www/(必要に応じてフォルダなど)/ -d (自身のドメイン)

メールアドレスを要求されるので管理者のアドレスを入力。

†この時、自身のドメインとサーバの紐付けが浸透している必要がある。
†また、サーバのバーチャルホストも正常でないとうまく機能しない。


■ファイアウォールの設定

#firewall-cmd --add-service=https --zone=public --permanent
#systemctl restart firewalld.service


■バーチャルホストの設定

/etc/httpd/conf.d/に virtualhost.conf を作成したりして書き込む。
証明書設定は複数使わないなら/etc/httpd/conf.d/ssl.confに項目があるのでそこに書き込むだけでもよい。

#systemctl restart httpd
書き換えたら再起動を忘れずに。


□バーチャルホストの書き方参考


DocumentRoot /var/www/example.com/
ServerName example.com
ServerAlias *.example.com

SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem



■証明書の自動更新

/etc/crontabなどに
00 01 * * * root certbot renew && systemctl restart httpd > temp.txt
を追加すれば、自動的に更新される。

なお、設定が間違っていたり、バージョンが変わって更新できなかったりすることもあるので、証明書が切れる3日前あたりのカレンダーに証明書が正常に更新されているかメモしておききちんと確認すること。

© 2003-2024 p-lux.net, Ryogo.

ページトップへ