Computer
Apache 2.2.0 SSL 通信の設定 Webminの設定 ErrorDocument AccessLogの形式

Apache 2.2.0

Apache2.2.0が2005/12/02にリリースされました.
ということで新たにインストールしなおしました.
基本的には以前の構成と同じです.

とりあえず今までのを終了してバックアップのため移動.
# /usr/local/apache2/bin/apachectl stop
# mv /usr/local/apache2 /usr/local/apace2-bak
ここらへん からDLして,
# tar xzvf httpd-2.2.0.tar.gz
# cd httpd-2.2.0
と展開して,
./configure --enable-rewrite \
--enable-so \
--enable-suexec \
--with-suexec-caller=nobody \
--with-suexec-docroot=/home \
--with-suexec-userdir=public_html \
--with-suexec-uidmin=500 \
--with-suexec-gidmin=500 \
--with-suexec-bin=/usr/local/apache2/bin/suexec \
--enable-modules="so ssl" \
--enable-ssl
とし,make,make installする.

configureでNo recognized SSL/TLS toolkit detectedと出てきた場合は,
apt-get install openssl-devel
をすればよい.

後は/usr/local/apache2/conf/httpd.conf を設定する.
87行目で管理者のメールアドレス,96行目でサーバ名を設定.
主な設定は,以前と異なり,/usr/local/apache2/conf/extra/ のディレクトリを読み込む形になっている.
例えば,383行目でLanguage settings,386行目でUserDir,392行目でバーチャルホストの設定など.
とりあえずLanguegeとUserDirは#を取っておき,念のため,
AddDefaultCharset off
UserDir disable
を記述した.
バーチャルホストは以前と記述方法は変わっていないようなので,
UserDir disabled
NameVirtualHost *:80
のみを自分で記述し,バーチャルホストの設定ファイルを読み込ませる(もしくはhttpd.confに記述する)ことにした.

もしくは・・・
386行目でUserDirの#は取らず,UserDir disable の記述もせずに, バーチャルホストの設定の中のDirectoryの中に
    Order allow,deny
    Allow from all
を付けてもよいようである.(もしくは.htaccess で対応かな.)
もちろん,392行目の#を取って,httpd-vhosts.conf のファイルを編集しても良い.
また,401行目も
Include conf/extra/httpd-default.conf
と#を取っておいた.

CGIを動かすためには,316行目の#を取り,
AddHandler cgi-script .cgi
とすればよい.
さらに
User nobody
(.configureしたときの--with-suexec-caller=nobodyと同じユーザ名, deamonにしておけは2.2.0デフォルトなのでこの設定は不要だが,なんとなく変更.) とすることで,suExecでCGIが動かせる. PHPのインストールについては以前の構成を参照.
httpd.conf には,
AddType application/x-httpd-php .php .html
AddType application/x-httpd-php-source .phps
LoadModule php5_module        modules/libphp5.so
を記述した.

403 ForbiddenのページにApacheやOSのバージョンが表示されるので, /usr/local/apache2/conf/extra/httpd-default.conf の中から
ServerTokens Min
を探して設定する.


2006/11/06 追記:バーチャルホストでcgi-binディレクトリでCGIを動かすためには, 各バーチャルホストでCGIを許可することのほかに,httpd.confの249行目付近の
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
をコメントアウトする必要がある.

SSL通信

SSL通信のためにはOpenSSLのインストールをしておく必要がある.
まず,
apt-get install openssl
とでもすればいいでしょう.
OpenSSLをhttp://www.openssl.org よりダウンロードしてインストールしても良いかな.

さらに自己証明書の作成をする. SSLを有効にしてapacheをインストールすると /usr/local/apache2/conf/extra/httpd-ssl.conf にSSLに関する設定ファイルがあります. このファイルはhttpd.confの中の
#Include conf/extra/httpd-ssl.conf
の#をとることで自動的に読み込まれます.

httpd-ssl.confには
SSLCertificateFile /usr/local/apache2/conf/server.crt (99行目)
SSLCertificateKeyFile /usr/local/apache2/conf/server.key (107行目)
でSSLで使用する秘密鍵と証明書ファイルのパスがあらかじめ指定されています.
そこで,
# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
..........................++++++
................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
および,
# openssl req -new -x509 -days 365 -key server.key -out server.crt
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:(以下適宜答える)
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:
Email Address []:
とします.
ここで,とりあえず起動するかチェック.
# /usr/local/apache2/bin/apachectl start
(apachectl startssl は2.2.0からなくなったので注意!)
# /usr/local/apache2/bin/apachectl start
Apache/2.2.0 mod_ssl/2.2.0 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.

Server www.example.com:443 (RSA)
Enter pass phrase:

OK: Pass Phrase Dialog successful.
こんな感じになればOK.
(後はhttpd-ssl.conf の77~81行目あたりをきちんと設定すればOK.
また,
# openssl rsa -in server.key -out server.key
Enter pass phrase for server.key:
writing RSA key
とすることで,apacheの起動時にSSLのためのパスワードを聞かれなくすることができます.

Webminの設定

WebminのApacheのモジュール設定.
Apacheサーバのルートディレクトリ /usr/local/apache2
httpdの実行可能ファイルのパス /usr/local/apache2/bin/httpd
apachectlコマンドのパス /usr/local/apache2/bin/apachectl
apacheを起動するためのコマンド,apacheを停止するためのコマンド,設定を適用するコマンドは自動にした.

起動及びシャットダウンの設定.
新規の起動またはシャットダウン アクションを作成をクリックし,適当な名前をつけ,説明も入力する.
起動,シャットダウンコマンドは
/usr/local/apache2/bin/apachectl start
/usr/local/apache2/bin/apachectl stop
とする.

ErrorDocument

どうもApache2.2.0はErrorDocumentの挙動が変わっているらしい.
500 Internal Server Errorは,どこをどうやって設定しても, カスタマイズしたエラーページに飛ばない.
(しかもApacheが勝手に表示するHTMLファイルはFirefoxで見るとHTMLファイルと認識されてない.)
403 Forbiddenも.htaccessでは設定不能.
サーバの設定ファイル(もしくはバーチャルホストの設定ファイル)に記述すればよいみたい.
どうしたものか・・・.

AccessLogの形式

アクセスログの形式にはCommon Log FormatというのとCombined Log Formatというのがあるらしい.
形式はそれぞれ
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
である.
詳しいことは公式サイトのログファイル を参照すると良い.
設定としては,httpd.confの200行~220行目あたりに
    CustomLog logs/access_log common
    #CustomLog logs/access_log combined
というのがあるので,有効にしたいほうのコメントアウトを削除すればよい.
Valid HTML 4.01 Transitional Valid CSS!
Copyright© Satze.net All rights reserved.