debianのapacheでdigest認証

Apache 1.3.8以上

mod_auth_digestを利用。apache-commonに入ってる。

httpd.confの設定

httpd.confに

 LoadModule digest_auth_module /usr/lib/apache/1.3/mod_auth_digest.so

を追加。

 # /etc/init.d/apache reload

パスワードファイル作成

realmとusernameの関係は次項参照。-cで新規作成。

 htdigest -c /home/n/public_html/.htpasswd "Members Only" n9d
 Adding password for n9d in realm Members Only.
 New password:
 Re-type new password:
 

他のユーザーに読めないようにしたほうがよいかも。

 $ chmod 660 .htpasswd
 $ chgrp www-data .htpasswd

とか。

.htaccessの作成

サンプル。DigestFileのpathはフルパスじゃないと駄目だと思う。

 AuthType Digest
 AuthName "Members Only"
 AuthDigestFile /home/n/public_html/.htpasswd
 <Limit GET POST>
         Require valid-user
 </Limit>