Memo

メモ > サーバ > 構築: Webサーバ設定 > Apache+SSL(有料証明書なしでSSLを導入する場合)

■Apache+SSL(有料証明書なしでSSLを導入する場合)
※暗号化して通信する ※有料証明書なしでSSLを導入するのは、あくまでも開発用途など 本番環境なら、後述の「Apache+SSL(有料証明書でSSLを導入する場合)」を参照 ■インストール(サーバ用秘密鍵・証明書作成) Webサーバー間通信内容暗号化(Apache+mod_SSL) http://centossrv.com/apache-ssl.shtml CentOS(さくらのVPS)に、mod_sslをインストール http://havelog.ayumusato.com/develop/server/e168-centos-mod_ssl-install.html オレオレ証明書をopensslで作る(詳細版) - ろば電子が詰まっている http://d.hatena.ne.jp/ozuma/20130511/1368284304
# yum -y install mod_ssl … mod_sslインストール # cd /etc/pki/tls/certs/ … ディレクトリ移動 # sed -i 's/365/3650/g' Makefile … サーバ用証明書有効期限を1年から10年に変更 # 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]:Tokyo … 都道府県名を設定 Locality Name (eg, city) [Newbury]:Shibuya … 市区町村名を設定 Organization Name (eg, company) [My Company Ltd]:refirio.net … 組織名を設定(なんでもいい) Organizational Unit Name (eg, section) []: … 空Enter(もしくは部署名を設定) Common Name (eg, your name or your server's hostname) []:refirio.net … コモンネーム(Webサーバー名)を設定。SSL購入時に申請するものと一致させる Email Address []:refirio@example.com … 管理者メールアドレスを設定
■秘密鍵からパスワードを削除
# openssl rsa -in server.key -out server.key … サーバ用秘密鍵からパスワード削除(Webサーバ起動時にパスワードを要求されないように) Enter pass phrase for server.key: … サーバ用秘密鍵・証明書作成時のパスワードを入力(表示はされない) writing RSA key
■インストール(サーバ用秘密鍵・証明書設定)
# vi /etc/httpd/conf.d/ssl.conf … ApacheSSL設定ファイル編集
#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/certs/server.key … サーバー用秘密鍵を指定 #DocumentRoot "/var/www/html" DocumentRoot "/var/www/html" … #を削除(コメントを解除) #SSLProtocol all -SSLv2 SSLProtocol all -SSLv2 -SSLv3 … SSLv2、SSLv3を無効化する(POODLE SSLv3.0 脆弱性問題対処) #SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:!RC4:!3DES:!RSA … RC4暗号化を外す(弱い暗号を除外 / ここでの指定でいいかは検証したい)
# service httpd configtest … 設定ファイルの構文をチェック # systemctl restart httpd … Apacheを再起動して、パスワードを要求されないことを確認 httpd を停止中: [ OK ] httpd を起動中: [ OK ]
■ファイヤーウォール設定(iptablesを使用している場合の設定)
# vi /etc/sysconfig/iptables … ファイヤーウォールを設定(443ポートを開ける)
#HTTPSを許可 -A MY-FIREWALL -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
# service iptables restart … ファイヤーウォールを再起動
https://refirio.net/ のようにブラウザからアクセスを確認

Advertisement