Apache2 設定

その後は Apache の設定をする。私が行った設定は以下。変更するファイルは3つ。

/etc/apache2/apache2.conf

50行目: ルートフォルダの変更
ServerRoot "/etc/apache2"

を以下に変更

ServerRoot "/var/www"
212行目: サーバ情報表示を抑制
ServerTokens Full

を以下に変更

ServerTokens Prod

これが Full になっていると、HTTP レスポンスヘッダに Apache の詳細な表示がされるので、それを抑止する。Prod 部分は ProductOnly でも良いらしいが、apache2.conf には以下のように書いてあるので Prod にしておいて間違いはないと思う。

Set to one of: Full | OS | Minor | Minimal | Major | Prod
222行目: ServerSignature

こちらもサーバ情報に関係しているようなので表示を抑制する。

ServerSignature On

を以下に変更

ServerSignature Off

/etc/apache2/mods-available/userdir.conf

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

        <Directory /home/*/public_html>
                AllowOverride FileInfo AuthConfig Limit
                Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
        </Directory>
</IfModule>

を以下のように変更する

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

	AliasMatch ^/([a-zA-Z0-9]+)/?(.*) /home/$1/public_html/$2

        <Directory /home/*/public_html>
                AllowOverride All
                Options ExecCGI MultiViews SymLinksIfOwnerMatch IncludesNoExec
        </Directory>
</IfModule>
userdir モジュールを有効にする。
$ sudo a2enmod userdir
Module userdir installed; run /etc/init.d/apache2 force-reload to enable.

/etc/apache2/sites-available/default

	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>

を以下に変更

	<Directory /var/www/>
		Options FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>

保存したら Apache2 をリスタートする。

$ sudo /etc/init.d/apache2 restart

動作テスト

以下のファイルを index.html にし、自分のホームフォルダに public_html フォルダを生成しその中へ保存する。

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="ja" xml:lang="ja" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://purl.org/net/ns/metaprof">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>The test page</title>
</head>
<body>

<h1>The test page</h1>
<p>Hello world =D</p>

</body>
</html>

http://localhost/userid/ にアクセスして表示確認をする。