Webサーバー間通信内容暗号化(Apache+mod_SSL)

最終更新日: 2017.05.17

<<トップページ <<新着情報 <<サイト内検索 <<CentOSで自宅サーバー構築 <<Scientific Linuxで自宅サーバー構築

■概要

ユーザ名やパスワード等の機密情報をWebブラウザから入力する場合、盗聴される恐れがあるため、Webサーバー間の通信内容を暗号化する。
ここでは、Webサーバーにmod_sslを導入して、URLをhttp://〜ではなく、https://〜でアクセスすることによって、Webサーバー間の通信内容を暗号化するようにする。


■mod_sslインストール

[root@fedora ~]# yum -y install mod_ssl ← mod_sslインストール

■WebサーバーSSL設定

(1)サーバー秘密鍵・証明書作成
[root@fedora ~]# cd /etc/pki/tls/certs/ ← ディレクトリ移動※FC4〜F15の場合

[root@fedora ~]# cd /usr/share/ssl/certs ← ディレクトリ移動※FC1〜FC3の場合

[root@fedora certs]# sed -i 's/365/3650/g' Makefile ← サーバー証明書有効期限を1年から10年に変更

[root@fedora certs]# make server.crt ← サーバー秘密鍵・証明書作成
umask 77 ; \
        /usr/bin/openssl genrsa -des3 1024 > server.key
Generating RSA private key, 1024 bit long modulus
.................++++++
............++++++
e is 65537 (0x10001)
Enter pass phrase: ← 任意のパスワードを応答※表示はされない
Verifying - Enter pass phrase: ← 任意のパスワードを応答(確認)※表示はされない
umask 77 ; \
        /usr/bin/openssl req -utf8 -new -key server.key -x509 -days 3650 -out server.crt -set_serial 0
Enter pass phrase for server.key: ← 上記で応答したパスワードを応答※表示はされない
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) [GB]:JP ← 国名応答
State or Province Name (full name) [Berkshire]:Kanagawa ← 都道府県名応答
Locality Name (eg, city) [Newbury]:Kawasaki ← 市区町村名応答
Organization Name (eg, company) [My Company Ltd]:fedorasrv.com ← サイト名応答(なんでもいい)
Organizational Unit Name (eg, section) []: ← 空ENTER
Common Name (eg, your name or your server's hostname) []:fedorasrv.com ← Webサーバー名応答
Email Address []:webmaster@fedorasrv.com ← 管理者メールアドレス応答

[root@fedora certs]# openssl rsa -in server.key -out server.key ← サーバー秘密鍵からパスワード削除
Enter pass phrase for server.key: ← サーバー秘密鍵・証明書作成時のパスワード応答※表示はされない
writing RSA key
※パスワードを削除するのは、Webサーバー起動時にパスワードを要求されないようにするため

(2)SSL設定
[root@fedora certs]# vi /etc/httpd/conf.d/ssl.conf ← ApacheSSL設定ファイル編集
※FC4〜F15の場合
SSLCertificateFile /etc/pki/tls/certs/server.crt ← サーバー証明書を指定

SSLCertificateKeyFile /etc/pki/tls/certs/server.key ← サーバー秘密鍵を指定

※FC1〜FC3の場合
SSLCertificateFile /usr/share/ssl/certs/server.crt ← サーバー証明書を指定

SSLCertificateKeyFile /usr/share/ssl/certs/server.key ← サーバー秘密鍵を指定

#  General setup for the virtual host, inherited from global configuration
#DocumentRoot "/var/www/html" ← #を削除(コメント解除)
↓
DocumentRoot "/var/www/html"

POODLE SSLv3.0 脆弱性問題対処
#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol all -SSLv2
↓
SSLProtocol All -SSLv2 -SSLv3 ← SSLv2、SSLv3を無効化する

(3)Apache設定(AWStats対応)
Apacheアクセスログ解析(AWStats)で解析できるようにhttpsアクセスログをhttpアクセスログと同じファイルに同じフォーマットで出力するようにする。
[root@fedora ~]# vi /etc/httpd/conf.d/ssl.conf ← SSL設定ファイル編集
# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/error_log ← ログファイル名変更
CustomLog logs/access_log combined env=!no_log ← ログ取得ディレクティブとログファイル名変更
LogLevel warn

■Apache設定反映

(1)Apache設定反映
[root@fedora ~]# /etc/rc.d/init.d/httpd restart ← Apache再起動
Restarting httpd (via systemctl):                          [  OK  ]

(2)ポート443番のOPEN
ルーター側の設定でポート443番をOPENする。
※ルーターの設定は各ルーターのマニュアルまたはメーカー別ルーターポート開放手順を参照

ポートチェック【外部からポート開放確認】で「host名」にサーバー名(例:fedorasrv.com)、「port番号」に443と入力して「ポートチェック」ボタン押下し、「ホスト=fedorasrv.com ポート=443 にアクセスできました。」と表示されることを確認。

■WebサーバーSSL確認

https://サーバーIPアドレス/にアクセスして「セキュリティの警告」ウィンドウが表示され、"はい"ボタン押下でWebページが表示されればOK

なお、https://サーバーIPアドレス/にアクセスして「セキュリティの警告」ウィンドウが表示されたら、"証明書の表示"⇒"証明書のインストール"を行えば、以降、「セキュリティの警告」ウィンドウは表示されなくなる。


■関連コンテンツ




▲このページのトップへ戻る

プライバシーポリシー