apacheを1から学んでみた。

Apacheのバージョン

# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Nov 23 2010 10:36:04

指針

/etc/httpd/conf/httpd.confに必要な項目を順次、追加していく。

ServerName

ServerName **.**.**.**

hostnameでも良いが、ipアドレスを書いてる。

ServerRoot

ServerRoot "/etc/httpd"

Listen

Listen 80

UserとGroup

User web-www
Group web-www

apache実行ユーザとそのグループを指定。

DocumentRoot

DocumentRoot "/var/www/html"

htmlファイル等のコンテツを格納する場所。
UserとGroupで指定したユーザでアクセス可能な必要がある。

ServerTokens

ServerTokens Prod

サーバが返すhttp headerにapacheのバージョンとOSを含めない。

ServerSignature

ServerSignature Off

エラーページのfooterに無駄な情報を表示しない。

TraceEnable

TraceEnable off

HTTP methodのTRACEを無効にする。
いまいち、よく分かっておらず。

TypesConfig

LoadModule mime_module modules/mod_mime.so
TypesConfig /etc/mime.types

htmlファイルへの要求にはcontent-type:text/htmlを返答等。
content-typeの返答を正しく行う。

DirectoryIndex

LoadModule dir_module modules/mod_dir.so
DirectoryIndex index.html

ディレクトリへのアクセスの時にindex.htmlを返答する。

charset

AddDefaultCharset utf-8

HostnameLookups

HostnameLookups off

アクセスしてきたipアドレスをhostnameに変換してから、
ログに書き込まないようにする。無駄なので。

Directory

<Directory / >
        Options None
        AllowOverride None
</Directory>

すべてのオプションを無効に。
.htaccessを無視。

cgi_module

LoadModule cgi_module modules/mod_cgi.so

CGIスクリプトの実行が可能なように、cgi_moduleをロード。

ドキュメントルートへの設定

<Directory /var/www/html>
        Options +ExecCGI +FollowSymLinks
        AddHandler cgi-script .rb 
</Directory>

ExecCGIでCGIの実行を許可。
FollowSymLinksでシンボリックリンクを有効に。
AddHandlerで拡張子.rbをCGIスクリプトとみなす。

access log

# access log
LoadModule log_config_module modules/mod_log_config.so
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/my_access_log common

アクセスログを残すにはモジュールをロードする必要がある。
ログファイルを相対パスでmy_access_logと指定してみた。