FreeBSD:Apache-2.2.8設定
提供:KinusatiWiki
目次 |
Apache-2.2.8設定
WebサーバとしてApache-2.2.8を利用する。
パッケージ導入
インストールはportsを利用する。
# portinstall www/apache22
オプション選択画面で以下の項目を選択されていることを確認する
- AUTH_BASIC
- AUTH_DIGEST
- AUTHN_FILE
- AUTHN_DBM
- AUTHN_ANON
- AUTHN_DEFAULT
- AUTHN_ALIAS
- AUTHZ_HOST
- AUTHZ_GROUPFILE
- AUTHZ_USER
- AUTHZ_DBM
- AUTHZ_OWNER
- AUTHZ_DEFAULT
- CACHE
- DISK_CACHE
- FILE_CACHE
- DAV
- DAV_FS
- ACTIONS
- ALIAS
- ASIS
- AUTOINDEX
- CERN_META
- CGI
- CHARSET_LITE
- DEFLATE
- DIR
- DUMPIO
- ENV
- EXPIRES
- HEADERS
- IMAGEMAP
- INCLUDE
- INFO
- LOG_CONFIG
- LOGIO
- MIME
- MIME_MAGIC
- NEGOTIATION
- REWRITE
- SETENVIF
- SPELING
- STATUS
- UNIQUE_ID
- USERDIR
- USERTRACK
- VHOST_ALIAS
- FILTER
- VERSION
- SSL
自動起動設定
/etc/rc.confに以下を追加
apache22_enable="YES" apache22_http_accf_http_load="YES" => これと、以下で説明するno-accf.confを加えることでApache起動時の以下Warningを抑制できる [Tue May 06 11:13:03 2008] [warn] (2)No such file or directory: Failed to enable the 'httpready' Accept Filter
httpd.conf設定
Apache設定のため/usr/local/etc/apache22/httpd.confを設定する。
基本設定
基本設定を行う。
ServerAdmin webmaster@foo.bar.com
多数のVirtualHostを設定するため、アクセスログを1ファイルに集約する。ただし、デフォルトのままではクライアントからのアクセス先URLが不明となるため、アクセスログにServerNameが表示されるように設定する。
LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" vcombinedio
CustomLog /var/log/httpd-access.log vcombinedio
/usr/local/etc/apache22/httpd.conf内のコメントアウトを外す
Include etc/apache22/extra/httpd-userdir.conf Include etc/apache22/extra/httpd-default.conf
/usr/local/etc/apache22/extra/httpd-default.confを設定する
ServerTokens Prod ServerSignature Off TraceEnable off
起動時のWarningを抑制するため/usr/local/etc/apache22/Includes/no-accf.confを以下の通り作成する。
<IfDefine NOHTTPACCEPT> AcceptFilter http none AcceptFilter https none </IfDefine>
アプリケーション設定
アプリケーションに利用する設定を/usr/local/etc/apache22/httpd.confに追加する。
AddHandler cgi-script .cgi AddType text/html .shtml AddOutputFilter INCLUDES .shtml
VirtualHost設定
/usr/local/etc/apache22/httpd.conf内のコメントアウトを外す
Include etc/apache22/extra/httpd-vhosts.conf
/usr/local/etc/apache22/extra/httpd-vhosts.confで、Name virtualを有効化する
NameVirtualHost *:80
/usr/local/etc/apache22/Includes/virtualhost.confにVirtualHost設定のコンフィグを設置の上設定する。設定項目は以下の通り。
- default VirtualHost
- 各種VirtualHost
<VirtualHost _default_:80>
ServerAdmin webmaster@foo.bar.com
DocumentRoot /usr/local/www/www.foo.bar.com/
ServerName foo.bar.com
# directory setting
<Directory "/usr/local/www/www.foo.bar.com">
Options Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@test.net
DocumentRoot /usr/local/www/www.foo.bar.net
ServerName www.foo.bar.net
<Directory "/usr/local/www/www.foo.bar.net">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "/usr/local/www/cgi-bin/www.foo.bar.net"
</VirtualHost>
ログローテーション
/etc/newsyslog.confに以下を追加
/var/log/httpd-error.log 644 186 * @T00 JB /var/run/httpd.pid /var/log/httpd-access.log 644 186 * @T00 JB /var/run/httpd.pid