ヘルプ:Webサーバー間通信内容暗号化(Apache+mod SSL)(CentOS7)

提供:EELの自由帳

メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(CentOS7)  > Webサーバー間通信内容暗号化(Apache+mod SSL)(CentOS7)

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

mod_sslインストール

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

[root@host3 certs]# yum -y install make ← makeインストール

WebサーバーSSL設定

サーバー用秘密鍵・証明書作成

[root@host4 ~]# cd /etc/pki/tls/certs/ ← ディレクトリ移動

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

[root@host4 certs]# make server.crt
umask 77 ; \
        /usr/bin/openssl genrsa -aes128 2048 > server.key
Generating RSA private key, 2048 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) [XX]:JP ← 国名応答
State or Province Name (full name) []:Tokushima ← 都道府県名応答
Locality Name (eg, city) [Default City]:Tokushima ← 市区町村名応答
Organization Name (eg, company) [Default Company Ltd]:sudachi.jp ← サイト名応答(なんでもいい)
Organizational Unit Name (eg, section) []: ← 空ENTER
Common Name (eg, your name or your server's hostname) []:sudachi.jp ← Webサーバー名応答
Email Address []:xxxx@sudachi.jp ← 管理者メールアドレス応答

[root@host3 certs]# openssl rsa -in server.key -out server.key ← サーバー用秘密鍵からパスワード削除
Enter pass phrase for server.key: ← サーバー用秘密鍵・証明書作成時のパスワード応答※表示はされない
writing RSA key

SSL設定

[root@centos certs]# vi /etc/httpd/conf.d/ssl.conf ← ApacheSSL設定ファイル編集

SSLCertificateFile /etc/pki/tls/certs/server.crt ← サーバー用証明書を指定

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

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

Apache設定反映

「httpd.conf」の文法チェック

[root@host3 ~]# apachectl configtest
Syntax OK

Apache再起動

[root@host3 ~]# systemctl restart httpd

動作確認

[root@host3 ~]# systemctl status httpd
 httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running)  since 土 2017-05-06 13:45:58 JST; 46s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 29305 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 29311 (httpd)
   Status: "Total requests: 9; Current requests/sec: 0.111; Current traffic: 1.3KB/sec"
   CGroup: /system.slice/httpd.service
           ├─29311 /usr/sbin/httpd -DFOREGROUND
           ├─29312 /usr/sbin/httpd -DFOREGROUND
           ├─29313 /usr/sbin/httpd -DFOREGROUND
           ├─29314 /usr/sbin/httpd -DFOREGROUND
           ├─29315 /usr/sbin/httpd -DFOREGROUND
           ├─29316 /usr/sbin/httpd -DFOREGROUND
           ├─29317 /usr/sbin/httpd -DFOREGROUND
           ├─29318 /usr/sbin/httpd -DFOREGROUND
           ├─29322 /usr/sbin/httpd -DFOREGROUND
           ├─29323 /usr/sbin/httpd -DFOREGROUND
           └─29324 /usr/sbin/httpd -DFOREGROUND

 5月 06 13:45:57 host3.sudachi.jp systemd[1]: Starting The Apache HTTP Server...
 5月 06 13:45:58 host3.sudachi.jp systemd[1]: Started The Apache HTTP Server.