2010年1月でついに新規リリース停止。2007年あたりからバイナリパッケージではほぼ入手困難になりつつあるのでコンパイルの知識が必要とされる。
スレッドを使えるようになったが、実際にはこれまでと同じプロセスを増やしていく起動(prefork)がデフォルトになっていることが多い。2.2がリリースされてちょっと中途半端な位置づけに感じる。
最新バージョンだが、すでにFedoraや比較的安定志向のVineですらバイナリパッケージを用意している。Tomcatと容易に連携できる。
たいていのOSにはバイナリパッケージも用意されていてその場合はOS毎に違ってくる。コンパイルの場合は何も指定していなければ/usr/local/apache/conf以下になる。
| RedHat系 | /etc/httpd/conf |
| Debian系 | /etc/apache/conf |
SetEnvIf Remote_Addr 192.168.1. no_log CustomLog /var/log/httpd/access_log common env=!no_log
SetEnvIf Remote_Addr 192.168.1. no_log RequestHeader add MyHeader "%D %t mytext" env=no_log
yum search mod_evasive --enablerepo=epel
LoadModule evasive20_module modules/mod_evasive20.so
<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 5
DOSSiteCount 30
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 30
# DOSEmailNotify "-s 'DoS Alert' hoge@example.com"
DOSLogDir "/var/tmp/"
# DOSWhitelist 127.0.0.1
# DOSWhitelist 192.168.1.*
</IfModule>
上記の例だと同一ページに1秒間5アクセス、もしくは同一サイトに1秒間30アクセスだとブロックリストに入り、30秒間はブロックされる。ブラックリストのIPからのアクセスがあった場合はまた30秒になるので、長い時間を指定する必要はない。
| DOSHashTableSize | 内部のメモリ、小さいと記憶できるIPが少なくなる |
| DOSPageCount | 一つのページに対する閾値 |
| DOSSiteCount | サイト全体に対する閾値 |
| DOSPageInterval | 一つのページに対するDOSと判定する計測時間 |
| DOSSiteInterval | サイト全体に対する計測時間 |
| DOSSystemCommand | OSコマンドを実施できる。内部での通知に使いたい場合など |
| DOSWhitelist | DOS検地除外IPなど |
sudo yum install -y httpd-devel gcc wget http://downloads.sourceforge.net/project/moddosdetector/moddosdetector/version-0.2/mod_dosdetector-0.2.tar.gz tar xvzf mod_dosdetector-0.2.tar.gz cd mod_dosdetector-0.2/ make make install
DoSDetection On
DoSPeriod 10
DoSThreshold 10
DoSHardThreshold 20
DoSBanPeriod 15
DoSTableSize 10
DoSIgnoreContentType image/*
RewriteEngine on
RewriteCond %{ENV:SuspectHardDoS} .+
RewriteRule .* - [R=503,L]
./configure --enable-mods-shared=all --enable-shared=yes --enable-ssl --enable-proxy ※SSLを有効にした場合opensslのライブラリが必要
再コンパイル時の注意./configure でやるとLoadModule一切なしのhttpd.confが作成される そのあと--enable-mods-shared=allしてもhttpd.confはそのままなので注意 いったん消してmake installする
./configure --prefix=/usr/local/apache22 --enable-mods-shared=all --enable-proxy-ajp --enable-proxy
LoadModuleは自動で入る。残りはhttpd.confに以下の設定をする # for PHP AddType application/x-httpd-php .php
コンパイルにbison,flex必要gnuからとってきて、bison,flexの順でconfigureのmake installする。/usr/local/binにパスを通しておくこと!
今回はPostgresを有効にしてコンパイル ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pgsql=/usr/local/pgsql --enable-mbstring PostgresもMYSQLも入ってれば以下でOK(MiracleLinux3.0 フルインストール) ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pgsql --with-mysql --enable-mbstring
flex,libxml-devel,libxml2-devel,postgresql-devel必要 ./configure --with-apxs2=/usr/local/apache2/bin/apxs --enable-mbstring --enable-mbregex --with-pgsql --with-openssl=/usr/local/ssl/ --without-mysql --with-libxml=/usr/local/lib
preforkとworkerとがありApache2.0より追加されたスレッドで動作するのがworkerだが、実態はほとんどpreforkが継続して使われている。以下のコマンドで複数プロセスが見えればpreforkである。
ps -ef | grep apache
実行ユーザーはwwwにする
groupadd www useradd -g www -s /sbin/nologin www
実行時のバージョンを隠す ServerSignature Off
Locationはファイルシステムの外にあるものを設定するときに使う。DocumentRoot以下に対する設定ならばDirectoryを使う。全体に対する設定にもLocationを使う。
<Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 192.168.0.1 </Location>
rootでchmod 751 username
<Directory /home/httpd/cgi-bin>
Options ExecCGI
</Directory>
CGI実行は
httpdの実行者がapacheユーザーとなるので755にしないと500エラー
#For UserDir CGI
ScriptAliasMatch ^/~([a-zA-Z0-9_-]+)/cgi-bin/(.+) /home/$1/cgi-bin/$2
<Directory /home/*/cgi-bin/>
Options ExecCGI
AddHandler cgi-script .cgi
</Directory>
| combined | LogFormat "%h %l %u %t ¥"%r¥" %>s %b ¥"%{Referer}i¥" ¥"%{User-Agent}i¥"" combined |
| common | LogFormat "%h %l %u %t ¥"%r¥" %>s %b" common |
#Log setting
SetEnvIf Remote_Addr 192.168.1. homelog nolog
SetEnvIf Request_URI "default.ida" wormlog nolog
SetEnvIf Request_URI "root.exe" wormlog nolog
SetEnvIf Request_URI "cmd.exe" wormlog nolog
SetEnvIf Request_URI "Admin.dll" wormlog nolog
SetEnvIf Request_Method "(GET)|(POST)|(PUT)|(DELETE)|(HEAD)" !worm
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(css)|(swf)$" nolog
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog logs/home_log common env=homelog
CustomLog logs/worm_log common env=wormlog
CustomLog logs/access_log combined env=!nolog
LoadModule ssl_module modules/mod_ssl.so
<IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so
Listen 443
SSLSessionCache shm:/var/cache/ssl_gcache_data(524288)
<VirtualHost _default_:443>
DocumentRoot /usr/local/apache2/htdocs
SSLEngine on
SSLCertificateFile conf/ssl/server.crt
SSLCertificateKeyFile conf/ssl/server.key
<Files ~ "\.(cgi|shtml)$">
SSLOptions +StdEnvVars
</Files>
<Directory /home/httpd/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfDefine>
<Directory "xxx"> Options Includes or IncludesNoExec AddHandler server-parsed .shtml AddType text/html .shtml </Directory> 上記設定でxxxディレクトリ以下で.shtmlのみ利用可能になる
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so #Proxy ProxyRequests off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /tu/ http://192.168.1.78/ ProxyPassReverse /tu/ http://192.168.1.78/
SSLProxyEngine On
1.3系は日本語問題ありなのでできれば2.0系で運用すべし
mod_jk.soはバイナリを入れる。configの設定はlinuxとまったく同じでよい
| BASIC認証回避 | http://id:pass@URL/ |
awk -F " " '{print $1}' access_log | uniq
awk -F " " '{print $1}' access_log | sort | uniq -c | sort
URL書き換えできるモジュール。ローカルアドレスをそのまま返すのでリバースプロキシーになりません。サイト移転時などに重宝する。
AllowOverride FollowSymLinks RewriteEngine On RewriteRule ^/app/(.*)$ http://転送先/$1
RewriteRule ^hoge\.html /hogehoge\.html?%{QUERY_STRING} [L,PT]
レスポンスヘッダーに付け加えたりできる。キャッシュコントロールなどをまとめて入れておくと便利。
時間切れまでつなぎっぱなしという恐るべきリソース消費。詳細は要調査 なおPHPを有効にするとプロセスのサイズが膨れるのでKeepAliveを短く(1秒ほど)して、プロセスが増えないようにしたほうが良い。