Apache 2.2 のインストールと,最低限の設定を記す.
portsから行った.
# cd /usr/ports/www/apache22
# make install clean
基本的にはデフォルトで動くが,主な設定は /usr/local/etc/apache22/httpd.conf の編集である.なお,補助的な設定ファイルは /usr/local/etc/apache22/extra に入っている.
html文書を置くディレクトリを設定する.デフォルトの場所に置いても良いのだが,もちろん別のディレクトリにしてもよい.
# # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/usr/local/www/data" # これはデフォルトの場所
なお,デフォルトのディレクトリは一般ユーザーでは入れないので,一般ユーザーからftpやsftpなどでログインしたい場合はディレクトリの所有者を変更しておく.
# chown hogehoge /usr/local/www/data
自分のホームディレクトリ内にファイルを置く場合はもちろんその必要は無い.なお,以下の説明はドキュメントルートを変更したことを前提におこなう.
ドキュメントルートを変更した場合,以下も変えておく.
# # This should be changed to whatever you set DocumentRoot to. # <Directory "/usr/home/hogehoge/www"> # 希望のディレクトリに変更する # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you.
あるディレクトリにファイル index.html などがない場合,一般のユーザーがこのディレクトリにアクセスすると,存在するファイルの一覧がブラウザに表示されてしまう.これを防ぐ.
<Directory "/usr/home/hogehoge/www">
と
</Directory>
のあいだに
Options Indexes
というのがあるが,この Indexes という単語を削除すればよい.
アクセスカウンタや掲示板などでCGIを使用する場合,以下のようにする.
ScriptAlias /cgi-bin/ "/home/hogehoge/cgi-bin/" # cgi-binディレクトリを変更 .... 略 .... <Directory "/home/hogehoge/cgi-bin"> # cgi-binディレクトリを変更 AllowOverride None # Options None # この行を Options ExecCGI # これに変更する(CGIを実行可) Order allow,deny Allow from all </Directory> .... 略 .... #AddHandler cgi-script .cgi # コメントをはずして AddHandler cgi-script .cgi # このようにする(拡張子の指定)
Apacheを運用していると,ログを直接見たくなるときがある.Webalizerなどのログ解析ツールを使用しない場合,ログのIPアドレスがあらかじめ逆引きされていると便利である.その場合,以下のようにする.ただしサーバーへの負担は増える.
直接の設定ファイルは /usr/local/etc/apache21/extra/httpd-default.conf であるが,この設定ファイルはいわば httpd.conf の「子分」ファイルである.この子分 httpd-default.conf そのものを有効にするための設定をしなければならない.
まず,/usr/local/etc/apache22/httpd.conf において,
# Various default settings #Include etc/apache22/extra/httpd-default.conf # この先頭のコメントをはずして Include etc/apache22/extra/httpd-default.conf # このようにする
次に,/usr/local/etc/apache22/extra/httpd-default.conf において,その最後のほうにある HostnameLookups Off を,
HostnameLookups On
にする.
/etc/newsyslog.conf を編集する. 以下は,
という設定である.
/var/log/httpd-access.log 644 7 * $W0D00 Z /var/run/httpd.pid /var/log/httpd-error.log 644 7 * $W0D00 Z /var/run/httpd.pid
Apacheを手動で起動させる命令は
# apachectl start
であるが,サーバー起動時に自動で起動させるには,/etc/rc.conf に以下の記述を追加する.
apache22_enable="YES"
Apache2.2 の起動時に以下の警告が出ることがある.ただし Apache 2.2 そのものは見かけ上問題なく動く.
[warn] (2)No such file or directory: Failed to enable the 'httpready' Accept Filter
対処法は以下の通り.
/boot/loader.conf で下記を有効にする
accf_http_load="YES"