Apache は説明が不用なぐらい有名な Web サーバーです。ここではApache 2.2系列を使用します。
ports を使ってインストールします。
# portinstall /usr/ports/www/apache22/
まず、鍵を作成します。ここではパスフレーズの入力を不要としています。
# openssl genrsa 1024 > /usr/local/etc/apache22/server.key
次に証明書を作成します。ここでは自己認証の証明書を作成しています。
# openssl req -new -x509 -days 30 -key /usr/local/etc/apache22/server.key > /usr/local/etc/apache22/server.crt
作成した鍵や証明書を一般ユーザーに見られないようにパーミッションの変更をします。
# chmod 600 /usr/local/etc/apache22/server.*
sslを使用するために、httpd.confの以下の該当箇所のコメントアウトを外します。
#Include etc/apache22/extra/httpd-ssl.conf
設定ファイルの変更が終わったら、一度Apacheを再起動します。
# apachectl restart
HTTPのDigest認証を使うと、認証時にネットワークを流れるパスワードが暗号化されます。IE6やFirefoxはDigest認証に対応しています。
Digest認証用のモジュールが有効となっているかどうか、/usr/local/etc/apache22/httpd.confを確認します。以下の様になっていればOKです。
LoadModule auth_digest_module libexec/apache22/mod_auth_digest.so
Digest認証用に設定ファイルを作成します。以下の内容のファイルを/usr/local/etc/apache2/Includes以下にhoge.confとして用意します。
<Directory /usr/local/www/data/hoge> AllowOverride AuthConfig AuthName "hogehoge" AuthType Digest AuthDigestDomain /hoge/ AuthDigestProvider file AuthUserFile /usr/local/etc/apache22/Includes/hoge.htdigest Require valid-user </Directory>
次にhtdigestを使って、Digest認証用のパスワードファイルを準備します。引数には上で指定したAuthName、パスワードファイル名、ユーザーIDを指定します。
# htdigest -c /usr/local/etc/apache22/Includes/hoge.htdigest 'hogehoge' foo
最後にApacheを再起動して、設定の変更点を有効にします。
# apachectl restart