0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

今更centos7でcertbot利用設定及び、更新をcrontabで自動化。

Last updated at Posted at 2025-09-26

一般的なcertbotをcentos7にて下記実行。

//通常の80ポート用のサイト作成。
cd /var/www
//直下に例としてサイトディレクトリ作成。
mkdir exsample

//バーチャルドメイン設定。
cd /etc/httpd/conf.d/
confファイル作成
vi www.example.com.conf
<VirtualHost *:80>
  DocumentRoot /var/www/animalnote
  ServerName www.animalnote.com
</VirtualHost>

//webサーバ停止。
systemctl stop httpd
certbot certonly --standalone -d www.exsample.com -m admin@gmail.com

cd /etc/letsencrypt/archive/
cd www.exsample.com
ls -l
//pemファイルの確認。
-rw-r--r-- 1 root root 1781 11月  2  2024 cert1.pem
-rw-r--r-- 1 root root 1801 11月  2  2024 chain1.pem
-rw-r--r-- 1 root root 3582 11月  2  2024 fullchain1.pem
-rw------- 1 root root 1704 11月  2  2024 privkey1.pem

//ssl.confファイルに下記内容追記保存。
vi /etc/httpd/conf.d/ssl.conf
<VirtualHost *:443>
     DocumentRoot "/var/www/example"
     ServerName www.exsample.com:443
     ErrorLog logs/www.exsample.com_secure-error_log
     CustomLog logs/www.exsample.com_secure-access_log combined
     SSLCertificateFile /etc/letsencrypt/archive/www.exsample.com/cert1.pem
     SSLCertificateKeyFile /etc/letsencrypt/archive/www.exsample.com/privkey1.pem
     SSLCertificateChainFile /etc/letsencrypt/archive/www.exsample.com/chain1.pem
</VirtualHost>

//webサーバ起動。
systemctl start httpd

certbot実行後バーチャルドメインのconfファイルにhttpshのリダイレクトが追記されるので、port80のhttpも残す場合は、コメントアウトする。

<VirtualHost *:80>
  DocumentRoot /var/www/animalnote
  ServerName www.animalnote.com
#RewriteEngine On
#RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

//certbotのrenewを自動化するには下記の様にcrontabにてshellを実行する例。

vi crtbotrenw_shell.sh
#!/bin/bash

echo "cerbot renew start"

systemctl stop httpd

/usr/bin/certbot renew --quiet

systemctl start httpd

echo "cerbot renew end"
//保存後実行可能に
chmod *x crtbotrenw_shell.sh
//crontabコマンドで。
crontab -e
//下記追記、毎日午前3時更新。
0 3 * * * ./crtbotrenw_shell.sh

以上centos7における、certbot利用による、https化処理の覚書。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?