はじめに
2016年4月13日追記
Let’s Encript の正式版がリリースされました。若干変更があるので、詳しくは下記記事を参照してください。
——
先日の記事では、CentOS 6.7 にパブリックベータの Let’s Encrypt をインストールしてみましたが、今度は CentOS 7.1 + Apache にインストールしてみます。Let’s Encrypt の細かいことについては、先日の記事を参照してください。
なお、CentOS はクリーンインストールしたところからの作業になります。
事前準備
事前に以下のパッケージをインストールしておきます。
# yum -y install httpd openssl mod_ssl # yum -y install git
デフォルトで、CentOS 7 は HTTP(80)/HTTPS(443) ポートを塞いでいるので、ファイアウォールのポートを開放します。
# firewall-cmd --zone=public --add-port=80/tcp --permanent # firewall-cmd --zone=public --add-port=443/tcp --permanent # firewall-cmd --reload
Apache を起動します。
# systemctl start httpd.service
Let’s Encrypt Client のインストール
どこのディレクトリでもよいので、以下のコマンドで Let’s Encrypt Client をインストールします。
# git clone https://github.com/letsencrypt/letsencrypt # cd letsencrypt # ./letsencrypt-auto --help
これで関連するパッケージを自動でインストールしてくれます。
CentOS 6.7 ではこの時点で警告が表示されスクリプトの実行ができませんでしたが、CentOS 7.1 では問題なくスクリプトを実行できました。これは、CentOS 6.7 では Python 2.6 だったのに対し、CentOS 7 は Python 2.7 のためです。
SSL証明書の作成と設定
Apache を終了しておかないと途中でエラーになってしまいますので、Apache を終了します。
# systemctl stop httpd.service
今回はドメイン名として、www.aruse.xyz を使用するので、以下のようにコマンドを実行します。
# ./letsencrypt-auto certonly --standalone -d www.aruse.xyz
すると、メールアドレスの入力を求められるので入力後、<了解>を選択します。
利用規約の同意画面が表示されるので、<Agree> を選択します。
以下のメッセージが表示されれば、SSL証明書の作成は成功です。なお、前回同じメールアドレスを使用していたので、余計なメッセージがありましたが省略してあります。
- Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/www.aruse.xyz/fullchain.pem. Your cert will expire on 2016-03-07. To obtain a new version of the certificate in the future, simply run Let's Encrypt again.
これで、SSL証明書の保存先も分かりましたので、内容を確認します。
# cd /etc/letsencrypt/live/www.aruse.xyz/ # ls cert.pem #サーバ証明書 chain.pem #中間証明書 fullchain.pem #サーバ証明書+中間証明書 privkey.pem #サーバ秘密鍵
内容が分かったので、ssl.conf と httpd.conf を以下のように変更します。
#/etc/httpd/conf.d/ssl.conf SSLCertificateFile /etc/letsencrypt/live/www.aruse.xyz/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.aruse.xyz/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/www.aruse.xyz/chain.pem
#/etc/httpd/conf/httpd.conf NameVirtualHost *:80 NameVirtualHost *:443 <VirtualHost *:80> ServerAdmin root@www.aruse.xyz DocumentRoot /home/c3008847/public_html/websec-room.com ServerName www.aruse.xyz </VirtualHost> <VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/letsencrypt/live/www.aruse.xyz/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.aruse.xyz/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/www.aruse.xyz/chain.pem ServerAdmin root@www.aruse.xyz DocumentRoot /home/c3008847/public_html/websec-room.com ServerName www.aruse.xyz </VirtualHost>
Apache を起動します。
# systemctl start httpd.service
SSL証明書のチェーンも問題なさそうです。
これで設定完了ですね。
複数ドメインのSSL証明書
複数ドメインのSSL証明書を作成してみます。なお、Let’s Encrypt はワイルドカード証明書はサポートしていません。
まず、Apache を終了します。
# systemctl stop httpd.service
www.aruse.xyz と aruse.xyz のサーバー名に対応した SSL証明書を作成するので、下記のコマンドを実行します。
# cd letsencrypt # ./letsencrypt-auto certonly --standalone -d www.aruse.xyz -d aruse.xyz
以下のメッセージが表示されるので、<Replace>を選択します。
以下のメッセージが表示されれば OK です。証明書のパスは変わっていませんね。
- Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/www.aruse.xyz/fullchain.pem. Your cert will expire on 2016-03-07. To obtain a new version of the certificate in the future, simply run Let's Encrypt again.
httpd.conf は以下のように設定します。ssl.conf は今回変更はありません。
#/etc/httpd/conf/httpd.conf NameVirtualHost *:80 NameVirtualHost *:443 <VirtualHost *:80> ServerAdmin root@www.aruse.xyz DocumentRoot /home/c3008847/public_html/websec-room.com ServerName www.aruse.xyz </VirtualHost> <VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/letsencrypt/live/www.aruse.xyz/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.aruse.xyz/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/www.aruse.xyz/chain.pem ServerAdmin root@www.aruse.xyz DocumentRoot /home/c3008847/public_html/websec-room.com ServerName www.aruse.xyz </VirtualHost> <VirtualHost *:80> ServerAdmin root@aruse.xyz DocumentRoot /home/c3008847/public_html/websec-room.com ServerName aruse.xyz </VirtualHost> <VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/letsencrypt/live/www.aruse.xyz/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.aruse.xyz/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/www.aruse.xyz/chain.pem ServerAdmin root@aruse.xyz DocumentRoot /home/c3008847/public_html/websec-room.com ServerName aruse.xyz </VirtualHost>
Apache を起動します。
# systemctl start httpd.service
おわりに
CentOS 6.7 と CentOS 7 に Let’s Encrypt の SSL証明書をインストールする方法は、Python のバージョンが異なること以外、ほとんど変わらないことが分かりました。
Let’s Encrypt は CentOS 7 (Python 2.7) の方が相性がよいようですね。CentOS 6 (Python 2.6) がダメだというわけではありませんが、実験的であるという警告も表示されるので、標準リポジトリを使用するなら CentOS 7 の方がよいかと思います。
Python 2.7 を直接インストールするなら、CentOS 6 でも問題ありません。ですが、CentOS の10年サポートから Python が外れてしまうことは意識しておいたほうがよいでしょうね。
コメント