- 追加された行はこの色です。
- 削除された行はこの色です。
*mod_sslのインストール [#i9c40ba7]
# yum install mod_ssl
*秘密鍵の作成 [#w1dcba33]
AES(Advanced Encryption Standard)で128ビットの鍵を生成する。
# cd /etc/httpd/conf
# openssl genrsa -aes128 2048 > server.key
パスフレーズを聞かれるので適当に入力
password
*公開鍵の作成 [#f14b8f25]
生成した秘密鍵をもとに作成~
Common Nameに *.example.com を指定すればワイルドカードになる?
# 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 []:
*デジタル証明書の作成 [#x6477566]
100年有効な証明書を作成します。
# openssl x509 -in server.csr -days 36500 -req -signkey server.key > 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の設定 [#fe935b51]
書き換えた部分のみ記載
# 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起動時のパスフレーズ解除 [#q413e17f]
このままではApacheの起動のたびにパスフレーズの入力が必要になります。~
以下でパスフレーズの入力が不要になります。~
実行する前にバックアップを取っておきましょう。
# cp server.key server.key.org
# openssl rsa -in server.key -out server.key
以下は昔書いた内容です。
----
*前提 [#g44d701b]
Apacheは --enable-ssl を付けてインストールしている必要があります。
*準備 [#fe3a35af]
# 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
*秘密鍵の生成 [#j8218478]
# openssl genrsa -rand work/${DOMAIN_NAME}.rand -des3 2048 > key/${DOMAIN_NAME}_key.pem
任意に決めたパスフレーズを入力します。~
パスフレーズは忘れてはいけません。
# chmod 700 key/${DOMAIN_NAME}_key.pem
*CSRの生成 [#kdde4872]
# 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
*証明書の生成 [#r950b983]
例では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
*パスフレーズの削除 [#j989ab48]
このままだとApache起動時にパスフレーズの入力を求められるので、秘密鍵からパスフレーズを削除します。
# openssl rsa -in key/${DOMAIN_NAME}_key.pem -out key/${DOMAIN_NAME}_key.nopass.pem
さきほどのパスフレーズを入力します。
*Apacheの設定変更 [#v62a097c]
# 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