1 views
実現する機能
ユーザ名やパスワード等の機密情報をWebブラウザから入力する場合、盗み見られる恐れがあるため、Webサーバー間の通信内容を暗号化するのが一般的です。ここでは、Webサーバーにmod_sslを導入して、URLをhttp://〜ではなく、https://〜でアクセスすることによって、Webサーバー間の通信内容を暗号化できるようにします。自サイトでもメールサーバーやサーバーの管理ツールは暗号化された情報でやりとりをしなくてはなりませんので、導入の必要に迫られ実施しました。
事前準備
※Webサーバー(Apache)とメールサーバー(Postfix & Dovecot)が構築済であることが前提です。
手順
以下の黒背景部分はGNOME端末を表示しています。紫色はキーボードから入力するコマンド(コピペした方が楽ですが、コマンドは覚えられません)、緑はコマンドや処理内容の説明、白は自動表示する部分、赤は注意書きです。
(1)サーバー用秘密鍵・証明書作成
#ディレクトリ移動 [root@ufuso ~]# cd /etc/pki/tls/certs/ #サーバー用証明書有効期限を1年から10年に変更 [root@ufuso certs]# sed -i 's/365/3650/g' Makefile #サーバー用秘密鍵の作成 [root@ufuso certs]# make server.key 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: #サーバー用秘密鍵からパスワード削除 [root@ufuso certs]# openssl rsa -in server.key -out server.key #上記で応答したパスワードを入力(非表示) Enter pass phrase for server.key: writing RSA key #サーバー用秘密鍵の作成 [root@ufuso certs]# make server.crt umask 77 ; \ /usr/bin/openssl req -utf8 -new -key server.key -x509 -days 3650 -out server.crt -set_serial 0 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) []:Okinawa #市区町村名 Locality Name (eg, city) [Default City]:Naha #組織名が無ければドメイン名でも入力 Organization Name (eg, company) [Default Company Ltd]:ShikakiraCS #空欄にする場合はエンター・キーを押す Organizational Unit Name (eg, section) []: #ホストネーム=自分のドメイン名 Common Name (eg, your name or your server's hostname) []:ufuso.dip.jp #管理者のメルアド Email Address []:webmaster@ufuso.dip.jp #アクセス不可設定 [root@ufuso certs]# chmod 400 server.* |
※パスワードを削除するのは、Webサーバー起動時にパスワードを要求されないようにするため
(2)Webサーバー(httpd)の設定
#mod_sslインストール [root@ufuso ~]# yum -y install mod_ssl インストール: mod_ssl.x86_64 1:2.4.6-67.el7.centos.6 完了しました! #ApacheSSL設定ファイル編集 [root@ufuso certs]# vi /etc/httpd/conf.d/ssl.conf # General setup for the virtual host, inherited from global configuration # #を削除(コメント解除) DocumentRoot "/var/www/html" # #を削除(コメント解除)してホスト名を入力 ServerName ufuso.dip.jp:443 # Server Certificate: # Point SSLCertificateFile at a PEM encoded certificate. If # the certificate is encrypted, then you will be prompted for a # pass phrase. Note that a kill -HUP will prompt again. A new # certificate can be generated using the genkey(1) command. # #を付加して無効化 #SSLCertificateFile /etc/pki/tls/certs/localhost.crt #サーバー用証明書を指定 SSLCertificateFile /etc/pki/tls/certs/server.crt # Server Private Key: # If the key is not combined with the certificate, use this # directive to point at the key file. Keep in mind that if # you've both a RSA and a DSA private key you can configure # both in parallel (to also allow the use of DSA ciphers, etc.) # #を付加して無効化 #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key #サーバー用秘密鍵を指定 SSLCertificateKeyFile /etc/pki/tls/certs/server.key |
(3)Apache設定反映
#Apache再起動 [root@ufuso certs]# systemctl restart httpd |
(4)ポート443番のOPEN
ルーター側の設定でポート443番をOPENする。
※ルーターの設定は各ルーターのマニュアルを参照のこと。ソフトバンク光の場合はこちら。
a ここをクリックして、下図の画面を表示させ、赤枠1に構築したメールサーバーのドメイン名を入力し、赤枠2にポート番号「443」を入力して、赤枠3にチェックを入れ、赤枠4の「Portチェック実行」をクリック。
b 赤枠でアクセスが認できればOK。
(5)WebサーバーSSL確認
a 自サイト(例示ではhttps://ufuso.dip.jp/)にアクセスして下図の画面が表示されたら、赤枠の「エラー内容」をクリック。
b 下図の画面が表示されたら、赤枠の「例外を追加」をクリック。
c 下図の画面が表示されたら、赤枠の「セキュリティ例外を承認」をクリック。
d 「https://〜」形式で画面が表示されればOK。
(6)Mailサーバーの設定(Postfix & Dovecot)
#postfix設定ファイル(main)編集 [root@ufuso ~]# vi /etc/postfix/main.cf 以下を最終行に追加(TLS通信の有効化) smtpd_use_tls = yes smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt smtpd_tls_key_file = /etc/pki/tls/certs/server.key smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache #postfix設定ファイル(master)編集 [root@ufuso ~]# vi /etc/postfix/master.cf # ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (yes) (never) (100) # ========================================================================== smtp inet n - n - - smtpd #ポート587を使うなら行頭の#を削除 submission inet n - n - - smtpd # -o syslog_name=postfix/submission # -o smtpd_tls_security_level=encrypt #ポート587を使うなら行頭の#を削除 -o smtpd_sasl_auth_enable=yes # -o smtpd_reject_unlisted_recipient=no #行頭の#を削除 smtps inet n - n - - smtpd #行頭の#を削除(コメント解除) -o syslog_name=postfix/smtps #行頭の#を削除(コメント解除) -o smtpd_tls_wrappermode=yes #行頭の#を削除(コメント解除) -o smtpd_sasl_auth_enable=yes # -o smtpd_reject_unlisted_recipient=no #10-ssl.confの編集 [root@ufuso ~]# vi /etc/dovecot/conf.d/10-ssl.conf ## ## SSL settings ## # SSL/TLS support: yes, no, required. |
(7)ポート465番のOPEN
ルーター側の設定でポート465番をOPENにします。
※ルーターの設定は各ルーターのマニュアルを参照のこと。ソフトバンク光の場合はこちら。
a ここをクリックして、下図の画面を表示させ、赤枠1に構築したメールサーバーのドメイン名を入力し、赤枠2にポート番号「465」を入力して、赤枠3にチェックを入れ、赤枠4の「Portチェック実行」をクリック。
b 赤枠でアクセスが確認できればOK。
(8)MailサーバーSSL確認
コメントを残す