1 views

実現する機能

怪しいサイト扱いされないために、サーバにSSLサーバ証明書を導入します。SSLサーバ証明書は、信頼のおける第三者機関=認証局が発行する電子的な証明書で、ウェブサイトを安全に利用するための3つの機能、身元保証、通信データの暗号化、通信データの漏えい検出機能が備わっています。有料のものは数万円しますが、今回はLet’s Encrypt から 発行料 無料の SSL/TLS サーバー証明書を取得しました。
以下は、その備忘録です。

事前準備(下記サイトで確認のこと)

SSLサーバ証明書取得手順

TeraTermでコマンドを使う方法を理解しておくこと。以下の記述ではTeraTerm画面を表示しています。紫色はキーボードから入力するコマンド(コピペした方が楽ですが、コマンドは覚えられません)、緑はコマンドや処理内容の説明、白は自動表示する部分、赤は注意書きです。

1 証明書を取得するためのツール Certbot クライアントをインストール

#Certbotのダウンロード
[root@e4vlm0ra ~]# wget https://dl.eff.org/certbot-auto
`certbot-auto’ に保存中

certbot-auto 100%[==========================>] 67.09K –.-KB/s 時間 0.06s

2019-11-27 18:29:15 (1.18 MB/s) – `certbot-auto’ へ保存完了 [68699/68699]

#ダウンロードファイルを/usr/local/bin/certbot-autoへ移動
[root@e4vlm0ra ~]# mv certbot-auto /usr/local/bin/certbot-auto

#所有者をrootに変更
[root@e4vlm0ra ~]# chown root /usr/local/bin/certbot-auto

#実行権限を付与
[root@e4vlm0ra ~]# chmod 0755 /usr/local/bin/certbot-auto

2 証明書を取得

#nginx環境下での証明書取得手順(Apacheの場合は「–apache」)

[root@e4vlm0ra ~]# /usr/local/bin/certbot-auto --nginx
Bootstrapping dependencies for RedHat-based OSes that will use Python3... (you can skip this with --no-bootstrap)
...
...
...
インストール 38 パッケージ
ダウンロードサイズの合計: 44 M
インストール済みのサイズ: 108 M
#「y」入力
これでよろしいですか? [y/N]: y
...
...
...
インストール済み:
gcc-8.2.1-3.5.el8.x86_64
...
...
zlib-devel-1.2.11-10.el8.x86_64


完了しました!
Creating virtual environment...
Installing Python packages...
Installation succeeded.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
#有効期間切れを事前に通知してもらうためにメールアドレスを入力
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): your-mail-address

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#同意書なので「A」を入力
(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 our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#内容を知らないので私は「N」を入力
(Y)es/(N)o: N

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#あなたのドメイン名が表示されるので、その中からひとつを番号入力
1: topi.0t0.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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:
http-01 challenge for topi.0t0.jp
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/nginx.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#強制的に暗号通信を行う設定の2を入力
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/nginx.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#以下の表示が出れば取得は成功
Congratulations! You have successfully enabled https://topi.0t0.jp

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=topi.0t0.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/topi.0t0.jp/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/topi.0t0.jp/privkey.pem
Your cert will expire on 2020-02-25. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again with the "certonly" option. 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

#nginx.confファイルが自動で書き換えられたので、nginxを再起動
[root@e4vlm0ra ~]# systemctl restart nginx

3 サイトを表示させる

(1)証明書を取得したサイトに「http://あなたのサイト名」でアクセスし、「https://あなたのサイト名」でサイトが表示されたら成功。

ssl証明書自動更新の設定(crontab)

#自動更新コマンドの実行(更新時期30日未満になると更新)

[root@e4vlm0ra ~]# /usr/local/bin/certbot-auto renew --pre-hook "service nginx stop" --post-hook "service nginx start"

Saving debug log to /var/log/letsencrypt/letsencrypt.log

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Processing /etc/letsencrypt/renewal/topi.0t0.jp.conf
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Cert not yet due for renewal
#更新時期30日未満ではないので更新しないが、結果は成功
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

The following certs are not due for renewal yet:
/etc/letsencrypt/live/topi.0t0.jp/fullchain.pem expires on 2020-06-02 (skipped)
No renewals were attempted.
No hooks were run.
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

#crontabをインストール
[root@e4vlm0ra ~]# yum -y install cronie-noanacron
インストール済み:
cronie-noanacron-1.5.2-4.el7.x86_64

完了しました!

#crontabに設定を追加する。
[root@e4vlm0ra ~]# vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .—————- minute (0 – 59)
# | .————- hour (0 – 23)
# | | .———- day of month (1 – 31)
# | | | .——- month (1 – 12) OR jan,feb,mar,apr …
# | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
#毎月1日と15日の午前5時に更新するように設定。apacheを使用なら「nginx」を「httpd」に変更

  0  5  1  *  * root /usr/local/bin/certbot-auto renew --pre-hook "service nginx stop" --post-hook "service nginx start"
  0  5  15 *  * root /usr/local/bin/certbot-auto renew --pre-hook "service nginx stop" --post-hook "service nginx start"
 

ZeroSSLで証明書を取得する場合はこちらから

以上

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください