MENU
環境設定メモ
サーバ設定メモ
その他設定メモ
webサイトの構築
複数のドメインとサブドメンで運用する設定
基本設定HostnameLookups Off On ←ログ記録をIPアドレスからホスト名に変換 (アクセスの多いサイトではOffにする)
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined ←リクエストされたURIが長すぎる場合はログに記録しない
ServerTokens Full Prod ←HTTPヘッダの情報を最小に設定する
ServerSignature On Off ←エラーメッセージ出力時にフッタを表示しないようにする
メインサイトの設定ファイルを作成する
# cd /etc/apache2/sites-available/
# cp default main
# vi main
NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/maindomain/ ←メインサイトのデレィクトリ
ServerName main.jp ←メインサイトのドメインを追記
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/maindomain/>
Options -Indexses FollowSymLinks MultiViews ←ファイル一覧を表示しないようにする
AllowOverride None FileInfo ←.htaccessによるファイル情報の変更を許可する ※1
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# RedirectMatch ^/$ /apache2-default/ ←リダイレクトの解除
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log main-error.log ←エラーログファイルを変更
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
SetEnvIf Request_URI "default\.ida" no ←以下7行ワーム対策で追記
SetEnvIf Request_URI "root\.exe" no
SetEnvIf Request_URI "cmd\.exe" no
SetEnvIf Request_URI "Admin\.dll" no
SetEnvIf Request_URI "NULL\.IDA" no
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no
CustomLog /var/log/apache2/access.log main-access.log combined env=!no ←アクセスログファイルの変更
# ServerSignature On ←エラーメッセージのフッター表示を解除
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
※1 phpmyadminは表示できなくなる
二つ目のサイトの設定ファイルを作成する
# cd /etc/apache2/sites-available/
# cp main second
# vi second
NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/maindomain/ seconddomein/ ←二つ目のサイトのデレクトリ
ServerName main.jp www.second.org:80 ←サイトのドメインとポート番号
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/seconddomain/>
Options -Indexses FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# RedirectMatch ^/$ /apache2-default/
</Directory>
ErrorLog /var/log/apache2/main-error.log second-error.log ←エラーログファイルを変更
LogLevel warn
SetEnvIf Request_URI "default\.ida" no
SetEnvIf Request_URI "root\.exe" no
SetEnvIf Request_URI "cmd\.exe" no
SetEnvIf Request_URI "Admin\.dll" no
SetEnvIf Request_URI "NULL\.IDA" no
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no
CustomLog /var/log/apache2/main-access.log second-access.log combined env=!no ←アクセスログファイルの変更
# ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
サブドメインの設定ファイルを作成
# cd /etc/apache2/sites-available/
# cp second sub
# vi sub
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/seconddomein/ sub-seconddomain/ ←追加したデレクトリ
ServerName www.second.org:80 sub.seconddomain.org:80 ←サブドメインとポート番号
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/sub-seconddomain/>
Options -Indexses FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/second-error.log sub-error.log ←エラーログファイルを変更
LogLevel warn
SetEnvIf Request_URI "default\.ida" no
SetEnvIf Request_URI "root\.exe" no
SetEnvIf Request_URI "cmd\.exe" no
SetEnvIf Request_URI "Admin\.dll" no
SetEnvIf Request_URI "NULL\.IDA" no
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no
CustomLog /var/log/apache2/second-access.log sub-access.log combined ←アクセスログファイルを変更
# ServerSignature On
</VirtualHost>
公開するサイトを設定する
Which site would you like to disable?
Your choices are: 000-default
Site name? 000-default
# a2ensite
Which site would you like to enable?
Your choices are: default main second sub
Site name? main second sub
# /etc/init.d/apache2 force-reload
無効なページをリクエストした場合トップページにリダイレクトする
.htaccessに
ErrorDocument 403 http://akieye.ddo.jp
ErrorDocument 404 http://akieye.ddo.jp
を記述してディレクトリに置く
設定ファイルのAllowOverride NoneをAllowOverride allに変え.htaccessファイル
を許可する。