Let’s Encryptで無料SSL設定 – Rocky Linux 9 (さくらのVPS)
Rocky Linux 9 (さくらのVPS)で、無料SSL(Let’s Encrypt)を導入する手順です。
初期設定
EPELインストール
sudo dnf install epel-release
sudo dnf clean allEPEL設定
EPELを使用すると明示しないと、EPELパッケージを取得しないようにする。
設定ファイル/etc/yum.repos.d/epel.repoの7行目enabled=1をenabled=0にする。
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=https://download.example/pub/epel/$releasever/Everything/$basearch/
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgcheck=1
countme=1参考
Webサーバー
Apacheをインストール
sudo dnf -y install httpdhttpd.confを編集
sudo vi /etc/httpd/conf/httpd.confServerName:ホスト名を変更
構文チェックの実施
httpd -tApacheの起動
sudo systemctl start httpd.serviceApacheを自動的に起動
sudo systemctl enable httpd.serviceテストページの表示確認
http://[ドメイン名]/にアクセスし確認する。
Let’s Encrypt – SSL証明書取得
さくらのVPS のスタートアップスクリプト「Let’s Encrypt」が使えなかった。
選択できない状態だった。
Let’s Encrypt – さくらのVPSマニュアル
手動で構築する。
Certbotインストール
sudo dnf --enablerepo=epel install certbotバージョン確認
$ certbot --version
certbot 2.9.0サーバー証明書取得
sudo certbot certonly --webroot -w /var/www/html -m info@ example.com -d example.com -n --agree-tos取得した証明書の確認
/etc/letsencrypt/live/example.com/に、以下の4ファイルが作成されていることを確認する。
- cert.pem
- chain.pem
- fullchain.pem
- privkey.pem
証明書更新自動化サービスの設定
証明書が自動的に更新された際にApacheを再起動するようにする
/etc/sysconfig/certbot の編集
28行目アンコメント、29行目コメントアウト
# An example to restart httpd would be:
POST_HOOK="--post-hook 'systemctl restart httpd'"
# POST_HOOK=""証明書更新の自動化
sudo systemctl enable --now certbot-renew.timer参考
【Rocky Linux 9】12.SSL取得(Let’s Encrypt)
SSL設定
mod_sslインストール
sudo dnf install mod_ssl設定編集
/etc/httpd/conf.d/ssl.confの編集
# 43行目 : コメント解除
DocumentRoot "/var/www/html"
# 44行目 : コメント解除しサーバー名指定
ServerName www.example.com:443
# 85行目 : 取得した証明書を指定
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
# 93行目 : 取得した鍵ファイルを指定
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
# 102行目 : 取得した中間証明書を指定
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem再起動・確認
sudo systemctl restart httpd.servicehttps://[ドメイン名]/にアクセスし確認する。
参考
その他
dnfがKilled される問題
解決方法
dnf config-manager --disable epel
