コンテンツをsslで暗号化したhttpsとして通信させるために、過去数十万を支払って証明書を頂いていたのだが、
ここ最近、それも無償にすることができる。
それが、https://letsencrypt.org/で、それをより簡単に実装させようとした仕組みの一つがhttps://certbot.eff.org/
なそうな。
*寄付(donate)をpaypal経由でしたら、NGとなった...なんとかならんのか...
ここではapache httpdにsslを組み込んでhttps通信をさせてみる。
そのために、apache httpdにmod_sslを組み込み、
[root@c ~]# yum install mod_ssl
そして、Let's Encryptを容易に組み込めるcertbotをインストールします。
幸い、このツールは epel で配布されているので、
[root@c ~]# yum install epel-release
[root@c ~]# yum install certbot
にてインストールできます。
Let's Encrypt様から証明書を頂けるのは、インターネットに晒されたマシンのみ。(Let's EncryptからDNSで引けるサイト)
内部のマシンは無理みたい(n1.sybyl.localとか)。
まずは、稼働中のhttpdを停止して
[root@c ~]# systemctl stop httpd
certbotツールを使って、証明書を入手します。
こちらではメールを登録させませんでした。重大な問題発生時にメールで配信されるので登録すべきかもしれませんが。
[root@c ~]# certbot certonly --standalone -d web.chaperone.jp --register-unsafely-without-email \
--standalone-supported-challenges http-01
WARNING: The standalone specific supported challenges flag is deprecated.
Please use the --preferred-challenges flag instead.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Registering without email!
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for web.chaperone.jp
Waiting for verification...
Cleaning up challenges
Generating key (2048 bits): /etc/letsencrypt/keys/0000_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0000_csr-certbot.pem
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/web.chaperone.jp/fullchain.pem. Your cert
will expire on 2017-08-19. To obtain a new or tweaked version of
this certificate in the future, simply run certbot again. To
non-interactively renew *all* of your certificates, run "certbot
renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
[root@c ~]#
*久々に実行したら「--standalone-supported-challenges」は「--preferred-challenges」に置き換わったみたい
入手した証明書は /etc/letsencrypt/live/<ドメイン名> に配置されます。
このファイルを apache httpd に組み込むことになります。
[root@c ~]# ls -l /etc/letsencrypt/live/web.chaperone.jp/
合計 4
-rw-r--r-- 1 root root 543 5月 21 23:05 README
lrwxrwxrwx 1 root root 40 5月 21 23:05 cert.pem -> ../../archive/web.chaperone.jp/cert1.pem
lrwxrwxrwx 1 root root 41 5月 21 23:05 chain.pem -> ../../archive/web.chaperone.jp/chain1.pem
lrwxrwxrwx 1 root root 45 5月 21 23:05 fullchain.pem -> ../../archive/web.chaperone.jp/fullchain1.pem
lrwxrwxrwx 1 root root 43 5月 21 23:05 privkey.pem -> ../../archive/web.chaperone.jp/privkey1.pem
[root@c ~]#
証明書のありかを定義します
[root@c ~]# vi /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/letsencrypt/live/web.chaperone.jp/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/web.chaperone.jp/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/web.chaperone.jp/chain.pem
[root@c ~]#
これでhttpdを再起動すれば、https通信でコンテンツ配信ができますが、
通常のhttp通信でこられた方を自動的にhttps側に渡す rewrite の設定は下記となる
[root@c ~]# vi /etc/httpd/conf.d/rewrite.conf
<ifModule mod_rewrite.c>
RewriteEngine On
LogLevel alert rewrite:trace3
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</ifModule>
[root@c ~]#
[root@c ~]# systemctl start httpd
これで完了
[root@c ~]# certbot certonly --standalone -d web.chaperone.jp -d web.sysosa.jp \
--register-unsafely-without-email --agree-tos --preferred-challenges http-01
「-d」で複数のサイトを指定する
httpdを止めないで更新する方法もありますが、確認用のファイルを置くのが面倒なので
取得時同様にhttpdを一旦停止して、証明書更新ファイルを受け取ることにしました
[root@c ~]# crontab -e
10 18 */3 * * /bin/systemctl stop httpd && /bin/certbot renew && /bin/systemctl start httpd
[root@c ~]#
yumパッケージがありませんでした。
https://certbot.eff.org/lets-encrypt/centosrhel8-otherに
あるようにwgetでコマンドを入手します。
取得した certbot-auto コマンドを /usr/local/bin とか /opt/bin などに配置して、
[root@c ~]# systemctl stop httpd.service
[root@c ~]# /opt/bin/certbot-auto certonly --standalone -d web.chaperone.jp -d web.sysosa.jp \
--register-unsafely-without-email --agree-tos --preferred-challenges http-01
[root@c ~]#
で証明書を入手して、「/etc/httpd/conf.d/ssl.conf」らを書き換えて設定は完了。
その後に httpd.service を立ち上げる。
CentOS7となんら変わらないです
自動更新ですが、下記のようにしてます
[root@c ~]# crontab -e
10 18 */3 * * /bin/systemctl stop httpd && /opt/bin/certbot-auto renew && /bin/systemctl start httpd
[root@c ~]#