0
0

はじめてのWebサーバで常時SSL化(https)にする(さくらのWebサーバ、nginx、tomcat)

Last updated at Posted at 2024-05-17

はじめてのWebサーバで常時SSL化(https)する

1. 前提条件

既に導入が済んでいるもの

今回特に影響があったのは、自分がnginxをリバースプロキシとして、tomcatにアクセスする設定を行っていた部分です。
このために他の常時SSL化の方法と合わない部分がありました。同様の設定を行っている方に対しては、役に立つと思います。

このページで設定するもの

今回はCopliot先生にお世話になりました。

1. Aレコード、AAAAレコードの設定

これまでIPV4しか扱ってこなかったが、設定を強く勧めるもののようだった。
さらには、ホスト名として使用していたsvw.modgoodluck.comのみならず、modgoodluck.comに対してもAレコード、AAAAレコードの登録が必要とのこと。本当に必要かどうかの検証は行っていないが、上手くいったケースとしてそのまま載せておく。計4件の登録となった。
※AAAAレコードは、IPv6版のAレコード。さくらのVPSならログインした最初の画面でIPv6を確認できる。

No. ドメイン名 レコード名
① modgoodluck.com Aレコード
② modgoodluck.com AAAAレコード
③ svw.modgoodluck.com Aレコード
④ svw.modgoodluck.com AAAAレコード
これらを「お名前ドットコム」で登録。

2.SSL証明書のインストール、SSL証明書の自動更新設定

以下を実行。

sudo dnf install epel-release
sudo dnf install certbot python3-certbot-nginx
certbot --nginx

上手くいくと、以下のような表示が出る。

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

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: svw.modgoodluck.com 
#ここは、/etc/nginx/conf.d/tomcat.confに記載されたドメイン名が表示される。
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Requesting a certificate for svw.modgoodluck.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/svw.modgoodluck.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/svw.modgoodluck.com/privkey.pem
This certificate expires on 2024-08-15. #証明書期限が表示される
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
#ウラで自動更新が設定されました、とのこと

Deploying certificate
Successfully deployed certificate for svw.modgoodluck.com to /etc/nginx/conf.d/tomcat.conf
Congratulations! You have successfully enabled HTTPS on https://svw.modgoodluck.com

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

3.確認

実際に、https://でURLを入力して、アクセスできることを確認。

4.おわりに

調べる時間はそれなりに必要だったが、やってみたらとてもシンプルだった。
誰かのお役に立ちますように。

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