LoginSignup
0
0

More than 3 years have passed since last update.

SSL設定をする

Posted at

事前準備

ドメインを取得しておく。
(今回はRoute53でドメインを購入
  ⇨レコード追加でipアドレスと結びつける)

設定を行っている

サーバーへの設定はCertbotというツールを利用します。
Amazon Linux2ではEPEL7という拡張パッケージをインストールすることで利用できるようになります。

以下作業はホームディレクトリで行いました

$ cd

EPEL7をインストール

$ sudo wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/
$ sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-*.rpm
$ sudo yum-config-manager --enable epel*

最後に下記コマンドで正常に準備できているか確認します。

$ sudo yum repolist all

問題なければepel関連がenabledとして表示されます。

Certbotをインストール

$ sudo yum install -y certbot python2-certbot-apache

証明書を作成

次に実際にCertbotを実行して証明書を作成します。

$ sudo certbot

最初にファイルが存在しないというエラーが出力されるが問題なし。
最初にメールアドレスを入力する

Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): 

規約の同意を求められるのでyesをおす

Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?

Apache設定の際に入力したバーチャルホストの設定を元に、SSL化するホスト名の確認が行われます。
問題なければEnterを入力する。


Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: yourhost.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input

作成して問題なければ下記のメッセージを含む表示が出て完了となります。

Congratulations! You have successfully enabled https://yourhost.example.com

Apacheを再起動して反映されます。

$ sudo service httpd restart

ブラウザでSSL化したものを確認。

証明書を自動で更新させる

Let's Encryptの証明書は3ヶ月しか有効期限がありません。
そのためCrontabを利用します。

$ sudo vi /etc/crontab

下記の行を追記します。

39 1,13 * * * root sudo certbot renew --no-self-upgrade --post-hook "/bin/systemctl reload httpd"

最後にcrondを再起動して設定を反映させます。

$ sudo systemctl restart crond

下記コマンドで正常に動作するか確認

$ sudo certbot renew --no-self-upgrade --post-hook "/bin/systemctl reload httpd" --force-renewal
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0