mod_sslのインストール†# yum install mod_ssl 秘密鍵の作成†AES(Advanced Encryption Standard)で鍵を生成する。 # cd /etc/httpd/conf # openssl genrsa -aes256 2048 > server.key パスフレーズを聞かれるので適当に入力 password 公開鍵の作成†生成した秘密鍵をもとに作成 # openssl req -new -key server.key > server.csr Enter pass phrase for server.key:パスフレーズを入力 Country Name (2 letter code) [XX]:JP State or Province Name (full name) []:Tokyo Locality Name (eg, city) [Default City]:Shinjyuku-ku Organization Name (eg, company) [Default Company Ltd]:self Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []:example.com Email Address []:test@example.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:適当に入力 An optional company name []: デジタル証明書の作成†100年有効な証明書を作成します。 # openssl x509 -in server.csr -days 36500 -req -signkey server.key -sha256 > server.crt Signature ok subject=/C=JP/ST=Tokyo/L=Shinjyuku-ku/O=self/CN=example.com/emailAddress=test@example.com Getting Private key Enter pass phrase for server.key:パスフレーズ Apacheの設定†書き換えた部分のみ記載 # vi /etc/httpd/conf.d/ssl.conf DocumentRoot "/home/example/public_html" ServerName example.com:443 SSLCertificateFile /etc/httpd/conf/server.crt SSLCertificateKeyFile /etc/httpd/conf/server.key Apache起動時のパスフレーズ解除†このままではApacheの起動のたびにパスフレーズの入力が必要になります。 # cp server.key server.key.org # openssl rsa -in server.key -out server.key ポート確認†# netstat -tanp # firewall-cmd --zone=public --add-service=https --permanent # firewall-cmd --reload # firewall-cmd --list-all 以下は昔書いた内容です。 前提†Apacheは --enable-ssl を付けてインストールしている必要があります。 準備†# cd /usr/local/apache2/ # mkdir -p ssl/{work,key,cert} # chmod 700 ssl/key # DOMAIN_NAME='example.localhost' # cd ssl # RAND_VALUE=`vmstat | tail -n 1` # echo $RAND_VALUE | openssl md5 > work/${DOMAIN_NAME}.rand # chmod 700 work/${DOMAIN_NAME}.rand 秘密鍵の生成†# openssl genrsa -rand work/${DOMAIN_NAME}.rand -des3 2048 > key/${DOMAIN_NAME}_key.pem 任意に決めたパスフレーズを入力します。 # chmod 700 key/${DOMAIN_NAME}_key.pem CSRの生成†# openssl req -new -key key/${DOMAIN_NAME}_key.pem -out work/${DOMAIN_NAME}_csr.pem さきほどのパスフレーズを入力します。 入力例 Country Name (2 letter code) [XX]:JP State or Province Name (full name) []:Tokyo Locality Name (eg, city) [Default City]:Shibuya Organization Name (eg, company) [Default Company Ltd]: Organizational Unit Name (eg, section) []:system1 Common Name (eg, your name or your server's hostname) []:example.localhost Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: # chmod 700 work/${DOMAIN_NAME}_csr.pem 証明書の生成†例では10年間有効。 # openssl req -x509 -in work/${DOMAIN_NAME}_csr.pem -key key/${DOMAIN_NAME}_key.pem -out cert/${DOMAIN_NAME}_crt.self.pem -days 3650 さきほどのパスフレーズを入力します。 # chmod 700 cert/${DOMAIN_NAME}_crt.self.pem パスフレーズの削除†このままだとApache起動時にパスフレーズの入力を求められるので、秘密鍵からパスフレーズを削除します。 # openssl rsa -in key/${DOMAIN_NAME}_key.pem -out key/${DOMAIN_NAME}_key.nopass.pem さきほどのパスフレーズを入力します。 Apacheの設定変更†# vi /usr/local/apache2/conf/httpd.conf Listen 443 LoadModule ssl_module modules/mod_ssl.so # vi /usr/local/apache2/conf/extra/httpd-vhosts.conf <VirtualHost *:443> SSLEngine on SSLCertificateFile "/usr/local/apache2/ssl/cert/example.localhost_crt.self.pem" SSLCertificateKeyFile "/usr/local/apache2/ssl/key/example.localhost_key.nopass.pem" ServerAdmin test@example.com DocumentRoot "/home/example/public_html" ServerName example.localhost ErrorLog "logs/error_log" CustomLog "logs/access_log" combined </VirtualHost> # /etc/rc.d/init.d/httpd stop # /etc/rc.d/init.d/httpd start |