無料SSL証明書の「Let’s Encrypt 」を Apache 2.4環境に導入します。(2016-05-08作成)
Let’s Encrypt とは
認証局( CA )として「SSL/TLSサーバ証明書」を無料で発行するとともに、証明書の発行・インストール・更新のプロセスを自動化することにより、TLS や HTTPS(TLSプロトコルによって提供されるセキュアな接続の上でのHTTP通信)を普及させることを目的としているプロジェクトです。
1.環境整備
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ cat / etc / redhat - release
CentOS release 6.7 ( Final )
$ sudo / usr / sbin / httpd - V | head - n 1
Server version : Apache / 2.4.10 ( Unix )
$ openssl version
OpenSSL 1.0.1e - fips 11 Feb 2013
$ git -- version
git version 1.7.1
$ python -- version
Python 2.7.5
★Let 's Encrypt 導入サイト(参考)
https : //www.offline-net.com
2.Python をアップデートする
SCL をインストール
$ sudo yum install centos - release - SCL
python2 . 7 と scl utils をインストール
$ sudo yum update
$ sudo yum install scl - utils python27 python27 - scldevel
【参考】 SCLとは、Software Collections(以下 SCL) の略、Red Hat が提供する最新アプリケーション(安定版)のパッケージを提供、yumの旧パッケージと共存できる、サポート期間は「3年間」である。yum でのインストールしようとしたけど、古いのしか無い場合、自分でコンパイルする必要もなく、依存関係の解決から解放されます。
3.Let’s Encypt Client のインストール
$ sudo su
# scl enable python27 bash ←※python2.7をbash上で有効化
# cd /usr/local
# git clone https://github.com/letsencrypt/letsencrypt
# cd letsencrypt/
# ./letsencrypt-auto --help
★依存パッケージに問題がないようであれば、以下ログが出力されます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
…
Checking for new version . . .
Creating virtual environment . . .
Installing Python packages . . .
Installation succeeded .
Requesting root privileges to run letsencrypt . . .
/ root / . local / share / letsencrypt / bin / letsencrypt -- help
letsencrypt - auto [ SUBCOMMAND ] [ options ] [ - d domain ] [ - d domain ] . . .
The Let 's Encrypt agent can obtain and install HTTPS/TLS/SSL certificates. By
default, it will attempt to use a webserver both for obtaining and installing
the cert. Major SUBCOMMANDS are:
(default) run Obtain & install a cert in your current webserver
certonly Obtain cert, but do not install it (aka "auth")
install Install a previously obtained cert in a server
renew Renew previously obtained certs that are near expiry
revoke Revoke a previously obtained certificate
rollback Rollback server configuration changes made during install
config_changes Show changes made to server config during installation
plugins Display information about installed plugins
Choice of server plugins for obtaining and installing cert:
--apache Use the Apache plugin for authentication & installation
--standalone Run a standalone webserver for authentication
(nginx support is experimental, buggy, and not installed by default)
--webroot Place files in a server' s webroot folder for authentication
OR use different plugins to obtain ( authenticate ) the cert and then install it :
-- authenticator standalone -- installer apache
More detailed help :
- h , -- help [ topic ] print this message , or detailed help on a topic ;
the available topics are :
all , automation , paths , security , testing , or any of the subcommands or
plugins ( certonly , install , nginx , apache , standalone , webroot , etc )
★依存関係のエラーとなった場合…依存するパッケージのインストールを行う。
…
. / letsencrypt - auto : line 460 : virtualenv : コマンドが見つかりません
? ? ?
$ yum search virtualenv
…
python - paver . noarch : Python - based build / distribution / deployment scripting tool
$ sudo yum install python - paver
$ python -- version
Python 2.6.6
4.SSL証明書の作成と設定
Let’s Encryptの「SSL証明書」発行には、次の2通りの方法があります。
・standaloneモード (httpdサーバ無しで発行する)
・webrootモード (稼働中のhttpdサーバを使う)
standaloneモードは、証明書を取得するときに「80番ポート」と「443番ポート」を使うサーバを立ち上げます。つまり両方のポート(httpdサーバー)は停止する必要があります。webrootモードは、既に稼働中の httpdサーバで発行する場合、使用します。
【参考】 どちらの証明書発行モードでも「Let’s Encrypt」側からの「ドメイン認証」のために、サーバの「80番ポート」に外部からアクセスできる必要があります。ファイアウォール等で「80番ポート」をフィルタリングしている場合は、許可する必要があります。
★【standaloneモードでの発行】
# /usr/local/letsencrypt/letsencrypt-auto certonly --standalone -d www.offline-net.com
⇒メールアドレスの入力が求められるので入力して、<了解>を選択します。
⇒利用規約に同意するか聞かれるので、<Agree>を選択します。
成功例!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# ./letsencrypt-auto certonly --standalone -d www.offline-net.com
Checking for new version . . .
Requesting root privileges to run letsencrypt . . .
/ root / . local / share / letsencrypt / bin / letsencrypt certonly -- standalone - d www . offline - net . com
Version : 1.1 - 20080819
Version : 1.1 - 20080819
IMPORTANT NOTES :
- Congratulations ! Your certificate and chain have been saved at
/ etc / letsencrypt / live / www . offline - net . com / fullchain . pem . Your cert
will expire on 2016 - 07 - 14. To obtain a new version of the
certificate in the future , simply run Let 's Encrypt again.
- If you like Let' s Encrypt , please consider supporting our work by :
Donating to ISRG / Let 's Encrypt : https : //letsencrypt.org/donate
Donating to EFF : https : //eff.org/donate-le
# ls -1 /etc/letsencrypt/live/www.offline-net.com/
cert . pem
chain . pem
fullchain . pem
privkey . pem
失敗例!! ⇒名前解決できる FQDNと同一のサーバーである必要がある。
IMPORTANT NOTES :
- The following errors were reported by the server :
Domain : www . offline - net . com
Type : unauthorized
Detail : Correct zName not found for TLS SNI challenge . Found 'www
.offline-net.com, offline-net.com'
To fix these errors , please make sure that your domain name was
entered correctly and the DNS A record ( s ) for that domain
contain ( s ) the right IP address .
★【webrootモードでの作成】
# /usr/local/letsencrypt/letsencrypt-auto certonly --webroot -w /var/www/html/ -d www.offline-net.com
【参考】 http://使用するFQDN/.well-known 配下に「認証用ファイル」が設置されます。
5.Apacheサーバー設定
# vi /etc/httpd/conf/extra/httpd-ssl.conf
( 発行されたSSL 証明書をApache の設定ファイルに追加)
SSLCertificateFile / etc / letsencrypt / live / www . offline - net . com / cert . pem
SSLCertificateKeyFile / etc / letsencrypt / live / www . offline - net . com / privkey . pem
SSLCertificateChainFile / etc / letsencrypt / live / www . offline - net . com / chain . pem
6.SSL証明書の自動更新設定
# scl enable python27 'python -V'
Python 2.7.5
★ログイン毎に、自動的に「python2.7.x」を有効化にします
$ cat / etc / profile . d / enablepython27 . sh ⇒新規作成する。
#!/bin/bash
source / opt / rh / python27 / enable
export X_SCLS = "`scl enable python27 'echo $X_SCLS'`"
★自動更新を httpdサーバー無停止で行う
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# /usr/local/letsencrypt/letsencrypt-auto certonly --renew-by-default --webroot -w /var/www/html/ -d www.offline-net.com
Checking for new version . . .
Requesting root privileges to run letsencrypt . . .
/ root / . local / share / letsencrypt / bin / letsencrypt certonly -- renew - by - default -- webroot - w / var / www / html / - d www . offline - net . com
Version : 1.1 - 20080819
Version : 1.1 - 20080819
IMPORTANT NOTES :
- Congratulations ! Your certificate and chain have been saved at
/ etc / letsencrypt / live / www . offline - net . com / fullchain . pem . Your cert
will expire on 2016 - 08 - 05. To obtain a new version of the
certificate in the future , simply run Let 's Encrypt again.
- If you like Let' s Encrypt , please consider supporting our work by :
Donating to ISRG / Let 's Encrypt : https : //letsencrypt.org/donate
Donating to EFF : https : //eff.org/donate-le
# /etc/init.d/httpd reload
★Let’s Encrypt の証明書の有効期限は「90日間」のため、定期的に更新する必要があります。
# cat /var/spool/cron/root
00 05 01 * * / usr / local / letsencrypt / letsencrypt - auto certonly -- renew - by - default -- webroot - w / var / www / html / - d www . offline - net . com && / sbin / service httpd reload
付録.1 「Let’s Encrypt」の証明書の取得をやり直す場合…
「/etc/letsencrypt」 自体を削除して、httpdサーバーの「https」設定を無効にします。その後、本紙手順3.から再実行します。
以上