MENU

環境設定メモ

サーバ設定メモ

その他設定メモ

webサイトの構築

複数のドメインとサブドメンで運用する設定

基本設定
# vi /etc/apache2/apache2.conf enter ←基本設定ファイルを以下の様に編集


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 ←エラーメッセージ出力時にフッタを表示しないようにする

メインサイトの設定ファイルを作成する
# mkdir /var/www/maindomain enter ←メインサイトのファイルを設置するデレィクトリを作成しておく
# cd /etc/apache2/sites-available/ enter ←設定ファイルのデレィクトリに移動
# cp default main enter ←デフォルト設定ファイルを別名でコピ
# vi main enter ←コピーしたファイルを以下の様に編集


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は表示できなくなる


二つ目のサイトの設定ファイルを作成する
# mkdir /var/www/seconddomain enter ←二つ目のサイトのファイルを設置するデレィクトリを作成しておく
# cd /etc/apache2/sites-available/ enter ←設定ファイルのデレィクトリに移動
# cp main second enter ←メイン設定ファイルを別名でコピー
# vi second enter ←コピーしたファイルを以下の様に編集


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>


サブドメインの設定ファイルを作成
# mkdir /var/www/sub-seconddomain enter ←サブのサイトのファイルを設置するデレィクトリを作成しておく
# cd /etc/apache2/sites-available/ enter ←設定ファイルのデレィクトリに移動
# cp second sub enter ←セカンド設定ファイルを別名でコピー
# vi sub enter ←コピーしたファイルを以下の様に編集


<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>


公開するサイトを設定する
# a2dissite enter ←公開サイトの解除
Which site would you like to disable?
Your choices are: 000-default
Site name? 000-default enter ←解除する設定ファイル名を入力

# a2ensite enter ←公開サイトの選択
Which site would you like to enable?
Your choices are: default main second sub
Site name? main second sub enter ←有効にする設定ファイル名を入力

# /etc/init.d/apache2 force-reload enter ←サーバ状態を更新

無効なページをリクエストした場合トップページにリダイレクトする

.htaccessに
ErrorDocument 403 http://akieye.ddo.jp
ErrorDocument 404 http://akieye.ddo.jp
を記述してディレクトリに置く
設定ファイルのAllowOverride NoneをAllowOverride allに変え.htaccessファイル
を許可する。