基本情報

バージョン毎の特徴

2010年1月でついに新規リリース停止。2007年あたりからバイナリパッケージではほぼ入手困難になりつつあるのでコンパイルの知識が必要とされる。

スレッドを使えるようになったが、実際にはこれまでと同じプロセスを増やしていく起動(prefork)がデフォルトになっていることが多い。2.2がリリースされてちょっと中途半端な位置づけに感じる。

最新バージョンだが、すでにFedoraや比較的安定志向のVineですらバイナリパッケージを用意している。Tomcatと容易に連携できる。

設定ファイルの場所

たいていのOSにはバイナリパッケージも用意されていてその場合はOS毎に違ってくる。コンパイルの場合は何も指定していなければ/usr/local/apache/conf以下になる。

RedHat系/etc/httpd/conf
Debian系/etc/apache/conf

コンパイル

2.0.x系

./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する

2.2.x系

./configure --prefix=/usr/local/apache22 --enable-mods-shared=all --enable-proxy-ajp --enable-proxy

mod_sslを静的に組み込む

PHP

LoadModuleは自動で入る。残りはhttpd.confに以下の設定をする
# for PHP
AddType application/x-httpd-php .php

PHP4.x

コンパイルに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

PHP5.x

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 

Apacheの動作モード

preforkとworkerとがありApache2.0より追加されたスレッドで動作するのがworkerだが、実態はほとんどpreforkが継続して使われている。以下のコマンドで複数プロセスが見えればpreforkである。

ps -ef | grep apache

httpd.confの設定

インストール後のtodo

実行ユーザーはwwwにする

groupadd www
useradd -g www -s /sbin/nologin www
  1. AddDefaultCharSetコメントアウト(2.0.53より削除されている)
  2. LanguagePriority ja
  3. User www
  4. Group www
実行時のバージョンを隠す
ServerSignature Off

LocationとDirectoryの使い分け

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

CGIディレクトリ

<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>

ログの設定

#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

SSLの設定

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>

SSIの利用

<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

WebDAVの設定

1.3系は日本語問題ありなのでできれば2.0系で運用すべし

  1. mod_dav.soをインストール
  2. httpd.confに以下のように追加

Windowsで2.0とjkで連携

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

利用しているモジュール解説

mod_rewrite

URL書き換えできるモジュール。ローカルアドレスをそのまま返すのでリバースプロキシーになりません。サイト移転時などに重宝する。
AllowOverride FollowSymLinks
RewriteEngine On
RewriteRule ^/app/(.*)$ http://転送先/$1 
RewriteRule ^hoge\.html /hogehoge\.html?%{QUERY_STRING} [L,PT]

mod_header

レスポンスヘッダーに付け加えたりできる。キャッシュコントロールなどをまとめて入れておくと便利。

パフォーマンスについて

KeepAliveについて考察する

時間切れまでつなぎっぱなしという恐るべきリソース消費。詳細は要調査 なおPHPを有効にするとプロセスのサイズが膨れるのでKeepAliveを短く(1秒ほど)して、プロセスが増えないようにしたほうが良い。

有用リンク

Counter: 17660, today: 4, yesterday: 1

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS