SSL/TLSとは
SSL/TLSとは、安全にリモートのサーバと通信する仕組みです。データの暗号化、データの改ざん防止、そしてなりすまし防止の機能があります。
動作確認手順
- CentOS8 1号機にログイン
- Apacheのインストール
- httpsモジュールのインストール
- 秘密鍵鍵の作成
- サーバ証明書の作成
- SSLモジュールの設定
- httpdの再起動
- 動作確認
動作確認
# 1.CentOS8 1号機にrootでログイン
# 2.Apacheのインストール
Apacheをインストールします。インストールのやり方はコチラ
インストール後、ブラウザからアクセスできることを確認してください。
# 3.httpsモジュールのインストール
# スケジュールの確認
# デフォルトでは何もスケジュールされていません。
[root@localhost ~] # dnf -y install mod_ssl
(省略)
mod_ssl-1:2.4.37-21.module_el8.2.0+494+1df74eae.x86_64 sscg-2.3.3-14.el8.x86_64
完了しました!
# モジュールの確認
[root@CE08PRD101 ~] # httpd -M | grep ssl
AH00526: Syntax error on line 85 of /etc/httpd/conf.d/ssl.conf:
SSLCertificateFile: file '/etc/pki/tls/certs/localhost.crt' does not exist or is empty
# 4.秘密鍵鍵の作成
# 保存ディレクトリに移動
[root@CE08PRD101 conf] # cd /etc/httpd/conf/;pwd
/etc/httpd/conf
# 秘密鍵作成
[root@CE08PRD101 conf] # openssl genrsa > server.key
Generating RSA private key, 2048 bit long modulus (2 primes)
…………………..+++++
………….+++++
e is 65537 (0x010001)
# 5.サーバ証明書の作成
# CSRの作成
[root@CE08PRD101 conf]# openssl req -new -key server.key > server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
----------
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# サーバ証明書作成
[root@CE08PRD101 conf]# openssl x509 -req -signkey server.key < server.csr > server.crt
Signature ok
subject=C = XX, L = Default City, O = Default Company Ltd
Getting Private key
# 5.サーバ証明書の作成
# CSRファイルの作成
[root@localhost conf] # ll /tmp/cron.txt
-rw-r--r--. 1 root root 0 10月 2 16:12 /tmp/cron.txt
# 6.SSLモジュールの設定
# 秘密鍵(server.key)とサーバ証明書(server.crt)の確認
[root@CE08PRD101 conf] # ll
(省略)
-rw-r--r--. 1 root root 1115 10月 2 19:08 server.crt
-rw-r--r--. 1 root root 952 10月 2 19:05 server.csr
-rw-r--r--. 1 root root 1679 10月 2 18:59 server.key
# 秘密鍵(server.key)とサーバ証明書(server.crt)の移動
[root@CE08PRD101 conf] # mv server.key /etc/pki/tls/certs/
[root@CE08PRD101 conf] # mv server.crt /etc/pki/tls/certs/
# sslの設定ファイル編集
[root@CE08PRD101 conf]# vi /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
↓
SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
↓
SSLCertificateKeyFile /etc/pki/tls/private/server.key
# 7.httpdの再起動
[root@CE08PRD101 ~]# systemctl restart httpd
8.動作確認
Chromeを開き、以下のURLにアクセスします。
https://<WebサーバのIPアドレス>

「詳細情報を表示しない」 → 「<IPアドレス>にアクセスする(安全ではありません。)」

Webページが表示されればOKです。

サーバ証明書の確認をします。
「保護されていない通信」 → 「証明書」

先ほど作成したサーバ証明書の情報が確認できます。

以上、お疲れさまでした。