CentOS7.3でApache + mod_ssl + CertBot

環境

CentOS:7.3
Apache:2.4.6
mod_ssl:2.4.6
openssl:1.0.1e
SSL/TLS証明書の認証局:Let’s Encrypt ( CertBot )

全てyumを使ってインストールした。

 

Apacheとmod_sslのインストール

 

# httpdとmod_sslをインストール
$ sudo yum install httpd mod_ssl
# 次にhttpd.confや、ssl.conf、conf.modules.dの中身等を設定する。
# 80番ポートでアクセスできることは確認した。

 

CertBotをyumでインストール

 

# yum-config-managerを使うために、yum-utilsのインストール。
$ sudo yum install yum-utils
# リポジトリを追加。
$ sudo yum-config-manager --enable rhui-REGION-rhel-extras rhui-REGION-rhel-server-optional

# 上のやり方ができなかったので追記(2018年3月3日)
# EPELからインストールするようにすれば良い。
$ sudo yum -y install epel-release
# CertBotをyumでインストール。
$ sudo yum install certbot-apache
# httpdを起動。
$ sudo systemctl start httpd
# CertBot実行。(httpdを起動していないとエラーになる)
$ sudo certbot --apache

httpdを起動していないとこんなエラーが出た
[user@srv ~]$ sudo certbot –apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices) (Enter ‘c’ to
cancel):Eメールアドレス
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

——————————————————————————-
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: N

Which names would you like to activate HTTPS for?
——————————————————————————-
1: サイトのドメイン名.info
——————————————————————————-
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter ‘c’ to cancel):1
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for サイトのドメイン名.info
Error while running apachectl graceful.

Job for httpd.service invalid.

Cleaning up challenges
Error while running apachectl graceful.

Job for httpd.service invalid.

Encountered exception during recovery
Error while running apachectl graceful.

Job for httpd.service invalid.
Traceback (most recent call last):
File “/usr/lib/python2.7/site-packages/certbot/error_handler.py”, line 99, in _call_registered
self.funcs[-1]()
File “/usr/lib/python2.7/site-packages/certbot/auth_handler.py”, line 284, in _cleanup_challenges
self.auth.cleanup(achalls)
File “/usr/lib/python2.7/site-packages/certbot_apache/configurator.py”, line 1908, in cleanup
self.restart()
File “/usr/lib/python2.7/site-packages/certbot_apache/configurator.py”, line 1797, in restart
self._reload()
File “/usr/lib/python2.7/site-packages/certbot_apache/configurator.py”, line 1808, in _reload
raise errors.MisconfigurationError(str(err))
MisconfigurationError: Error while running apachectl graceful.

Job for httpd.service invalid.

Error while running apachectl graceful.

Job for httpd.service invalid.

IMPORTANT NOTES:
– 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.

httpd起動後
[user@srv]$ sudo certbot –apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

Which names would you like to activate HTTPS for?
——————————————————————————-
1: サイトのドメイン名.info
——————————————————————————-
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter ‘c’ to cancel):1
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for サイトのドメイン名.info
Waiting for verification…
Cleaning up challenges
Deploying Certificate for サイトのドメイン名.info to VirtualHost /etc/httpd/conf.d/ssl.conf

Please choose whether HTTPS access is required or optional.
——————————————————————————-
1: Easy – Allow both HTTP and HTTPS access to these sites
2: Secure – Make all requests redirect to secure HTTPS access
——————————————————————————-
Select the appropriate number [1-2] then [enter] (press ‘c’ to cancel): 1

——————————————————————————-
Congratulations! You have successfully enabled https://サイトのドメイン名.info

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=サイトのドメイン名.info
——————————————————————————-

IMPORTANT NOTES:
– Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/サイトのドメイン名.info/fullchain.pem. Your
cert will expire on 2017-09-26. To obtain a new or tweaked version
of this certificate in the future, simply run certbot again with
the “certonly” option. To non-interactively renew *all* of your
certificates, run “certbot renew”
– 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

それからhttps://サイトのドメイン名にアクセスできることを確認した。
https://www.ssllabs.com/ssltest/analyze.htmlこのサイトで、
評価を上げるためにssl.confを設定する。
何も設定していない状態では、Overall RatingはBだった。
VirtualHostを設定しているので、
そのディレクティブ内に

Include /etc/letsencrypt/options-ssl-apache.conf

を追加したら、Overall RatingはAになった。
GradeはAが80点以上らしいので、これで良しとする。

 

CertBotでTLS証明書を更新するように設定

https://certbot.eff.org/#centosrhel7-apache
ここによると1日2回、更新のためにCertBotを走らせると良いと書かれているが、
有効期間は90日だから毎月でも良いのかなーって思う。

$ sudo certbot renew --dry-run

とやって、何もエラーが出ないことを確認したら、

$ sudo certbot renew

をcronとかで定期的に実行するように設定すれば良い。

コメント

タイトルとURLをコピーしました