どうも、Let’s Encryptの証明書取得に使う、certbot だが、以前は github から落としてくるとか、dnf/yum でパッケージを落としてくる、といった方法で良かったようだが、そちらで提供されているバージョンは非推奨になっている模様。
certbot の本家サイトで案内されているのは、snap というパッケージ管理システムを使ってインストールする、という方法なので、それを試してみる。
1. snap & certbot のインストール
dnf --enablerepo=epel -y install snapd
systemctl enable --now snapd.socket
ln -s /var/lib/snapd/snap /snap
snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
2. SSL証明書の取得、SSL化
2.1. SSL証明書の取得
ひとまずは、ワイルドカードじゃなくて、通常のパターンで証明書を取ってみる。
systemctl stop httpd
certbot certonly -n --standalone --agree-tos -d hogehoge.work -m your-account@hogehoge.work --server https://acme-v02.api.letsencrypt.org/directory
なお、snap を使ってインストールした certbot を使う場合は、「証明書の更新」を自動でやってくれるので、cron のジョブを仕込んだり、手動で90日おきにオペレーションする…という手間が軽減されている。
2.2. SSL化
2.2.1. ssl.conf の設定
vi /etc/httpd/conf.d/ssl.conf
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt ### 元の記述をコメントアウト
↓
SSLCertificateFile /etc/letsencrypt/live/test.hogehoge.com/fullchain.pem ### この行追加
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key ### 元の記述をコメントアウト
↓
SSLCertificateKeyFile /etc/letsencrypt/live/test.hogehoge.com/privkey.pem ### この行追加
SSLCertificateChainFile /etc/letsencrypt/live/test.hogehoge.com/chain.pem ### この行追加
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 ### この行追加
2.2.2. welcome.conf の設定
vi /etc/httpd/conf.d/welcome.conf
<locationmatch "^/+$">
# Options -Indexes
# ErrorDocument 403 /noindex/index.html
</locationmatch>
2.2.3. httpd.conf の設定
vi /etc/httpd/conf/httpd.conf
### ドキュメントルートのDirectoryディレクティブ
<directory "/var/www/html/">
Options Indexes FollowSymLinks
↓
Options FollowSymLinks ## 変更
</directory>
### ファイルの末尾に追加
ServerTokens ProductOnly
ServerSignature Off
2.2.4. rewrite.conf の作成
vi /etc/httpd/conf.d/rewrite.conf
<ifmodule mod_rewrite.c="">
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</ifmodule>
systemctl restart httpd
systemctl restart php-fpm
ここまでやって、ドキュメントルートにおいたファイルにブラウザでアクセスすると、https に転送されて表示されることを確認。
タグ:
#apache #CentOS Stream #certbot #ConoHa VPS #Let's Encrypt