Let’s EncryptでSSL認証を無料で利用

ページコンテンツ

Let’s Encrypt


Let’s Encryptは、無料のSSL認証局です。Let’s Encryptはphytonをベースにしているので、Let’s Encryptを利用するには、phyton環境が必要です。

Let’s Encryptのインストール


EPEL (Extra Packages for Enterprise Linux) リポジトリを有効化します。

yum install epel-release

Certbot パッケージをインストールします。

yum install certbot-nginx

下記コマンドにて、SSL登録を行う。

certbot certonly –webroot -w 【ルートディレクトリ】-d 【ドメイン】

There were too many requests of a given type


短時間に複数回、SSLの登録、更新に失敗すると下記エラーメッセージが表示され、登録、更新ができなくなります。一定時間を空けた後に、再チャレンジするようにしてください。

There were too many requests of a given type :: Error creating new order :: too many failed authorizations recently: see https://letsencrypt.org/docs/rate-limits/

Let’s Encryptの証明書発行


80ポートで構成している場合は、Webサーバを停止した上で,下記コマンドを実施します。 80ポートで開通していないとエラーになります。つまり、80ポートで画面アクセスができる状態が必要です。

./certbot-auto certonly\
–agree-tos\
–standalone\
-w [ドメインルート]\
-d [ドメイン]\
-m [メールアドレス]

Webサーバを停止せずに証明書を発行するには、443ポートにて下記コマンドを実施します。

./certbot-auto certonly\
–agree-tos\
–standalone\
-w [ドメインルート]\
-d [ドメイン]\
-m [メールアドレス]

/etc/letsencrypt/live/[ドメイン]が作成されていれば、成功です。

ssl.confの設定


/etc/httpd/conf.d/ssl.confに下記設定を追加します。

<VirtualHost *:443>
ServerAdmin [ドメイン]
ServerName [ドメイン]
DocumentRoot [ドメインルート]
SSLEngine on
SSLCertificateKeyFile /etc/letsencrypt/live/[ドメイン]/privkey.pem
SSLCertificateFile /etc/letsencrypt/live/[ドメイン]/cert.pem
SSLCertificateChainFile /etc/letsencrypt/live/[ドメイン]/chain.pem
</VirtualHost>

Nginxの設定


access_log /var/log/nginx/【サイトURL】_access.log main;
error_log /var/log/nginx/【サイトURL】_error.log warn;

ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /etc/letsencrypt/live/【サイトURL】/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/【サイトURL】/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/【サイトURL】/chain.pem;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Protocol $scheme;

証明書の更新


Let’s Encryptの証明書の有効期限は3ヶ月のため、3ヶ月毎に証明書の更新が必要です。証明書の更新は下記コマンドにて実施します。

cd /opt/certbot
./certbot-auto renew

「/opt/certbot」については、各環境に合わせて下さい。

証明書の自動更新


定期的な更新が必要なため、Linuxのcrontabにて自動更新を行います。を利用します。 crontabを編集モードで起動します。

# crontab -e

crontabに自動更新の設定を行います。 毎月1日の04:00に証明書の自動更新を行い、04:10にnginxの再起動を行う設定例は下記の通りです。

0 4 1 * * service nginx stop
5 4 1 * * scl enable python27 bash “/opt/certbot/certbot-auto renew”
10 4 1 * * service nginx restart

crontabを編集を反映します。

# crontab -l

python27 をシェル(bash)で有効にする


Let’s Encryptを構成しているcertbotを実施するためには、python27 をシェル(bash)で有効にする必要があります、python27 をシェル(bash)で有効にする には、下記コマンドを実行します。

scl enable python27 bash

Let’s Encryptを構成しているcertbotを実施するためには、python27 をシェル(bash)で有効にする必要があります、python27 をシェル(bash)で有効にする には、下記コマンドを実行します。

scl enable python27 bash

証明書削除


rm -rf /etc/letsencrypt/archive/[ドメイン名]
rm -rf /etc/letsencrypt/live/[ドメイン名]
rm -rf /etc/letsencrypt/renewal/[ドメイン名] .comf

関連記事


Linux以外のIT技術については、下記サイトにアクセスしてください。
気まぐれSE研究所(https://www.se-lab.yokohama/)

外部参考サイト


https://blog.apar.jp/linux/3619/
https://jonkara.net/2017/10/12/ssl_lets_encrypt/
https://kohkimakimoto.hatenablog.com/entry/2016/09/15/180119
https://www.101010.fun/entry/lets-encrypt-centos6
https://www.s-oj.com/ec-business/system/lets-encrypt-centos6-5/
http://sig9.hatenablog.com/entry/2016/07/04/230000

https://qiita.com/TsutomuNakamura/items/7be17a20cdc5de563350
https://cspssl.jp/support/apache/config-multi.php
https://qiita.com/ariaki/items/5680cb6da6223844af4e
https://qiita.com/TsutomuNakamura/items/7be17a20cdc5de563350
https://business.biglobe.ne.jp/hosting/blog/tech/20150324111454
https://design.studio-umi.jp/blog/How-to-setup-multiple-SSL-on-Ubuntu-12.04
https://centossrv.com/apache-ssl.shtml