Let's EncryptでSSL証明書を取得する - CentOS
はじめに
Let's Encrypt
で、SSL証明書を取得するためのメモ。
環境
[root@blog ~]# hostnamectl status
Static hostname: blog.long-in.net
Icon name: computer-vm
Chassis: vm
Machine ID: ---
Boot ID: ---
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1062.18.1.el7.x86_64
Architecture: x86-64
リポジトリを追加
[root@blog ~]# yum install -y epel-release
certbot コマンドをインストール
[root@blog ~]# yum install -y certbot
SSL証明書の発行リクエスト
-d
オプションの引数にSSL証明書を取得したいドメイン名を指定。-w
オプションの引数にドキュメントルートを指定。
[root@blog ~]# certbot certonly --webroot -w /var/www/html -d blog.long-in.net
※上記は、ファイル認証の場合です。
Webサーバに設定
Webサーバによって読み込むファイルが違います。
ApacheとNginxの2つの場合は、以下のようになります。
Apache
SSLCertificateFile /etc/letsencrypt/live/blog.long-in.net/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/blog.long-in.net/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/blog.long-in.net/chain.pem
Nginx
ssl_certificate /etc/letsencrypt/live/blog.long-in.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.long-in.net/privkey.pem;
SSL証明書の更新リクエスト
[root@blog ~]# certbot renew
CRONで更新する場合
0 22 1 * * root /usr/bin/certbot renew && nginx -t && nginx -s reload
以上、終わり。
About
関西在住のエンジニア
言語: Ruby・Go・PHP
フレームワーク: RoR・Gin
趣味: 自作PC