Amazon Linux + Apache + Let’s Encrypt のインストール

事前準備

インストールは自動化されていますので、動かすための必要パッケージをインストールをします。

# yum -y install git

Let’s Encryptのインストール

# cd /etc
# git clone https://github.com/letsencrypt/letsencrypt.git

SSL証明書の取得

既にWebサーバ環境が整っているのでオプション「webroot」にて実行します。ドキュメントルート直下に「.well-known/」というディレクトリが作成され必要な処理が実行されます。

AmazonLinuxは正式にサポートがされていないのでデバッグモードでインストールする必要があります。

# cd /etc/letsencrypt
# ./certbot-auto certonly --webroot \
 -w /var/www/html/ -d rin-ka.net \
 -m sample@example.com  --debug\

ここで大問題が発生!インストールが正常にいきません。何とletsencrypt側のサーバが反応しない・・・・

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Exiting abnormally:
Traceback (most recent call last):
  File "/root/.local/share/letsencrypt/bin/letsencrypt", line 11, in <module>
    sys.exit(main())
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/certbot/main.py", line 742, in main
    return config.func(config, plugins)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/certbot/main.py", line 666, in certonly
    le_client = _init_le_client(config, auth, installer)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/certbot/main.py", line 382, in _init_le_client
    acc, acme = _determine_account(config)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/certbot/main.py", line 367, in _determine_account
    config, account_storage, tos_cb=_tos_cb)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/certbot/client.py", line 158, in register
    acme = acme_from_config_key(config, key)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/certbot/client.py", line 44, in acme_from_config_key
    return acme_client.Client(config.server, key=key, net=net)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/acme/client.py", line 71, in __init__
    self.net.get(directory).json())
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/acme/client.py", line 646, in get
    self._send_request('GET', url, **kwargs), content_type=content_type)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/acme/client.py", line 619, in _send_request
    response = self.session.request(method, url, *args, **kwargs)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/requests/adapters.py", line 499, in send
    raise ReadTimeout(e, request=request)
ReadTimeout: HTTPSConnectionPool(host='acme-v01.api.letsencrypt.org', port=443): Read timed out. (read timeout=45)
Please see the logfiles in /var/log/letsencrypt for more details.

日を改めて行ったところ、すんなりと成功しました。

-------------------------------------------------------------------------------
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

-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for rin-ka.net
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/rin-ka.net/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-auto again. To
   non-interactively renew *all* of your certificates, run
   "certbot-auto 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

SSL証明書の適用

Apacheのバージョンを確認します。バージョンにより設定方法が異なります。
Apache 2.4.8 未満だと fullchain.pem (サーバ証明書と中間証明書が結合したファイル)が利用できません。
確認したところ、fullchain.pemが利用できるようです。

# rpm -qa|grep httpd
httpd24-2.4.25-1.68.amzn1.x86_64

作成したSSL証明書をApacheに組み込みます。

# cd /etc/httpd/conf.d
# cp ssl.conf ssl.conf.org
# vi ssl.conf
<VirtualHost *:443>
ServerName rin-ka.net
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/rin-ka.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/rin-ka.net/privkey.pem
</VirtualHost>

Apacheを再起動します。

# /etc/init.d/httpd restart

SSL証明書の更新

Let’s Encrypt の証明書の有効期限は、90日間と短いため定期的に更新する必要があります。また、証明書が更新された場合はApacheに再読込を実施する必要があります。

SSL証明書の更新と、Nginxの設定再読込を実行するスクリプトを作成し、Cronで定期的にスクリプトを実行します。今回はweeklyで指定しました。

# cd /etc/cron.weekly
# vi letsencrypt
#!/bin/sh
/etc/letsencrypt/letsencrypt-auto renew > /dev/null
/etc/init.d/httpd reloadx
# chmod +x letsencrypt
スポンサーリンク

シェアする

フォローする

スポンサーリンク