mod_ssl の設定

mod_perlはちゃんと動作したので、次はmod_sslを動かしてみる。

数年前まで仕事でWebサイトを運用していたので、毎年VeriSignに証明書を申請していたのだけれど、もうすっかり手順を忘れてる。

以下のVeriSignのページを参考に設定した。

(1) 疑似乱数ファイルの作成

まあ、なんでもいいんだけど、以下の方法で作成。

$ openssl md5 /var/log/* > rand.dat

(2) 秘密鍵の生成

今やキー長は2048bitじゃないとVeriSignは申請を受け付けないようですな。

$ openssl genrsa -rand rand.dat -des3 2048 > key.pem

パスフレーズの入力を求められるので、適当に入れておく。

(3) CSRの生成

秘密鍵からCSRを生成する。

$ openssl req -new -key key.pem -out csr.pem

パスフレーズの入力を求められるので、先ほど入れたものを入力する。

その後、いろいろ聞かれるけど、いんちき証明書を作るだけなので、適当に入れればよろしい。ただし、Common Name にはホスト名を入れること。

Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Kanagawa
Locality Name (eg, city) []:Yokohama
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Koba-Lab
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:kathy.local
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

(4) 証明書の生成

ここで本来はVeriSignなどの認証機関にCSRを送って証明書をもらうのだけど、いんちき証明書をつくります。

$ openssl req -new -x509 -days 365 -key key.pem -out cert.pem

パスフレーズに続いて、同じようにいろいろ聞かれるので、同じように答えておく。

Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Kanagawa
Locality Name (eg, city) []:Yokohama
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Koba-Lab
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:kathy.local
Email Address []:

(5) 秘密鍵からパスフレーズをはずす

秘密鍵パスフレーズがついたままだと、自動でブートできないので、はずしてしまいます。

$ openssl rsa -in key.pem -out key.pem

(6) httpd.conf の設定

以下の行を有効にする(多分最初から有効になってるけど)。

LoadModule ssl_module libexec/apache2/mod_ssl.so

SSLの設定は別ファイルにするようになっているので、その設定を生かす。

# Secure (SSL/TLS) connections
Include /private/etc/apache2/extra/httpd-ssl.conf

(7) extra/httpd-ssl.conf の設定

以下の行はコメントアウトしておけばOK。

#ServerName www.example.com:443
#ServerAdmin you@example.com

SSLCertificateKeyFile、SSLCertificateFile に先ほど作成した秘密鍵と証明書を指定する。

SSLCertificateKeyFile "/private/etc/apache2/ssl/key.pem"
SSLCertificateFile "/private/etc/apache2/ssl/cert.pem"

Apacheを再起動すると、SSLが有効になっているはずです。