自宅サーバー構築記
13.apacheの各種設定について
a. apache1.3.29のインストールとserver-status、server-info
- apacheのステータス表示が可能になるようにオプションを追加する。
# cd /usr/local/src
# tar xzvf apache_1.3.29.tar.gz.tar
# cd apache_1.3.29
# ./configure --enable-module=most --enable-shared=max --enable-module=status
# make
# make install
- /usr/local/apache/conf/httpd.confにserver-statusを表示可能とする指定を追加する。
<Location /server-status>
□SetHandler server-status
□Order deny,allow
□Deny from all
□Allow from xxx.xxx.xxx.
</Location>
- またserver-infoを表示可能とする指定を追加する。
<Location /server-info>
□SetHandler server-info
□Order deny,allow
□Deny from all
□Allow from XXX.XXX.XXX.
</Location>
- 以上でhttpd://servername/server-statusでサーバーステータスが、httpd://servername/server-infoでサーバー情報が参照できる。
b. SSIの設定
- SSI(Server Side Include)の利用を可能とする。以下の部分がコメントでなければ有効になる。
AddType text/html .shtml
AddHandler server-parsed .shtml
c. ファイル一覧表示機能の解除
- 例えばhttp://o-hat.net/image/とurlに指定した場合imageディレクトリにDirectory_Indexディレクティブに指定したindex.html等が存在しない場合、imageディレクトリの一覧が表示されてしまう。これはセキュリティの観点から、できれば表示したくない。そのために以下の修正を行う。ちなみに"FollowSymLinks"はシンボリックリンクで示されたファイルにアクセスすることを可能にするという意味。"AllowOverride None"は.htaccess ファイルを完全に無視するという意味。
<Directory />
□Options FollowSymLinks ←Indexesオプションを削除する。
□AllowOverride None
</Directory>
d. ローカルアクセスログを取得しない設定
- アクセスログを記録してログの分析を行う場合、ローカルからアクセスしたものについてはログを残したくない。以下の指定でそれが可能になる。
SetEnvIf Remote_Addr ローカルアト゛レス nolog ←追加
CustomLog /usr/local/apache/logs/access_log combined env=!nolog
e. apacheエラーページの作成
- コンテンツの削除や移動でページにアクセスできない場合、apacheのエラー画面が出力されていたが、もっとわかりやすくするために自前のページを用意した。以下がその設定。
#
# Customizable error response (Apache style)
#
ErrorDocument 404 /error/htp_404.html
f. アクセス制限(DB認証)
- apache+postgreSQLでユーザ認証を導入してみた。ネタは@IT「apacheによるwebサーバ構築」第11回 ユーザー認証によるアクセス制限(データベース認証編)をそっくりそのままやってみましたというものなので、詳しくはそちらを参照してください。
- まずはmod_auth_pgsql-0.9.12のインストール
$ tar xzvf mod_auth_pgsql-0.9.12.tar.gz
$ cd mod_auth_pgsql-0.9.12
$ ./configure --with-apxs=/usr/local/apache/bin/apxs --with-pgsql=/usr/local/pgsql
$ /usr/local/apache/bin/apxs -I/usr/local/pgsql/include -L/usr/local/pgsql/lib -lpq -o mod_auth_pgsql.so -c mod_auth_pgsql.c auth_pgsql_shared_stub.c
# su root
# /usr/local/apache/bin/apxs -i -a -n auth_pgsql mod_auth_pgsql.so
- apacheのhttpd.confに以下の行を追加する。
<Directory "ハ゜スワート゛制限するテ゛ィレクトリ">
□Auth_PG_host 127.0.0.1
□Auth_PG_port 5432
□Auth_PG_database テ゛ータヘ゛ース名
□Auth_PG_user nobody
□Auth_PG_pwd nobody
□AUth_PG_pwd_table user_data
□Auth_PG_uid_field user_name
□Auth_PG_pwd_field passwd
□AuthName "タイトル"
□Authtype Basic
<Limit POST GET>
□require valid-user
</Limit>
</Directory>
- パスワードの暗号化についての指定。何も指定しないとCRYPT方式になる。
□Auth_PG_encrypted off ←パスワードの暗号化を使用しない場合
□Auth_PG_hash_type MD5 ←MD5パスワードを使用する場合
- CRYPT方式で暗号化されたパスワードは以下のコマンドで求めることができる。"xx"は任意に2文字。
$ perl -e 'print crypt("password", "xx");'
HOME>インデックス
|