Table of Contents
ドキュメント
-
Apache HTTP Server Documentation
- 現行バージョン
- Version 2.4
-
- Allow, Deny, Order ディレクティブ
Apache用モジュールをコンパイルできるようにする
- httpd-devel (apxs) をインストールしておく。
# yum install httpd-devel
バーチャルホスト設定
設定
- /etc/httpd/conf.d/VirtualHosts.conf
# Use name-based virtual hosting. NameVirtualHost *:80 <VirtualHost *:80> ServerName www.takeash.net DocumentRoot /var/www/html/ </VirtualHost> <VirtualHost *:80> ServerName vh1.takeash.net DocumentRoot /var/www/vh1-html/ <Directory "/var/www/vh1-html"> # AllowOverride All </Directory> </VirtualHost>
エラー対策
- バーチャルホストが表示されない。
- エラーメッセージ
[warn] _default_ VirtualHost overlap on port 80, the first has precedence
- 原因
NameVirtualHost ディレクティブが設定されていない。 - 対処
NameVirtualHost ディレクティブを設定する。
httpd.conf を修正するより conf.d に VirtualHosts.conf として専用のファイルを作成しておく方が忘れなくていいかも。
- エラーメッセージ
Digest 認証
- 認証、承認、アクセス制御
-
mod_auth_digest
- レルム/ユーザ/パスワード追加
htdigest [-c] passwdfile <realm> <username>
- /etc/httpd/conf.d/DigestAuth.conf
<Directory "/var/www/html/Download/<realm>"> AllowOverride AuthConfig AuthType Digest AuthName "<realm>" AuthUserFile /var/www/passwd/passwords_digest Require user <username> Options None Options Indexes DirectoryIndex index.html index.htm index.php Order allow,deny Allow from all </Directory>
- レルム/ユーザ/パスワード追加
Apacheでhttp-equiv属性値を反映させる
- META要素「http-equiv属性値とHTTPヘッダー」について考える
デフォルトでは、LastModifiedしか反映されない。
- apxsはhttpd-devel-xxx.rpmをインストールすることで使用できるようになる。
- うちの Fedora Core 3 環境だとmod_html_metaのコンパイルでエラーが出るんでまだ使えていない。引き続き検討。
Apache に DoS 攻撃対策 mod_evasive
cgi-bin ディレクトリでファイル名を省略したときに index.cgi を実行する設定
httpd.conf に ScriptAliasMatch を追加する。
修正前
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
修正後
ScriptAliasMatch ^/cgi-bin/(.*)\.cgi /var/www/cgi-bin/$1.cgi ScriptAliasMatch ^/cgi-bin/(.*)/? /var/www/cgi-bin/$1/index.cgi ScriptAliasMatch ^/cgi-bin$ /var/www/cgi-bin/index.cgi ScriptAlias /cgi-bin/ /var/www/cgi-bin/
index.cgi の例
#!/usr/local/bin/perl use strict; use warnings; use utf8; use CGI::Pretty; my $q = new CGI; my $host = $q->url(-base => 1); print $q->redirect( $host . '/' ); # EOF