ウェブサーバーの設定

カテゴリ: My Web Development / 公開日: 2012年3月21日(水曜)17:31 / 投稿者: Tom Goodsun

ウェブ用ディレクトリ構成がある前提で進めます。

Apacheをインストール

# yum install httpd

設定をへんこうします。

# vi /etc/httpd/conf/httpd.conf

以下追加または設定。

User webmaster
Group webmaster

ServerName myserver.net(ネットワーク設定でしたサーバー名を設定)

DocumentRoot "/home/www/localhost/public_html/"

<Directory />
    Options All
    AllowOverride All
</Directory>


<Directory "/home/www/localhost/public_html">
    Options -Indexes FollowSymLinks +ExecCGI

DirectoryIndex index.html index.htm index.php index.cgi index.pl index.rb

LogFormat "%h %l %u [%{%a %b %d %T %Y}t] \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

ErrorLog "|/usr/sbin/rotatelogs /home/www/localhost/logs/httpd/error_log.%m%d 86400 540"

SetEnvIf Request_URI "\.(css)|(js)|(gif)|(jpg)|(png)$" no_log
CustomLog "|/usr/sbin/rotatelogs /home/www/localhost/logs/httpd/access_log.%m%d 86400 540" combined env=!no_log

#Alias /icons/ "/var/www/icons/"

#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
↓
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable

#Alias /error/ "/var/www/error/"

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
#    Allow from .example.com
    Allow from localhost
    Allow from 192.168.1.
</Location>

バーチャルホストの設定

バーチャルホストは1台のウェブサーバー複数のドメインを運用する際に設定します。通常はhttpd.confに設定を記述しますが、httpd.conf自体が見づらくなるため、外部ファイル化しましょう。
まずはバーチャルホストの設定ファイルを設置するディレクトリを作る。

# cd /etc/httpd/
# mkdir vhosts

設定ファイルの設置。
バーチャルホストの設定ファイル名は*.confというルールにしています。
まずはサーバー名に指定したドメインをバーチャルホストとして設置してみます。

<VirtualHost *:80>
    ServerAdmin このメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。
    DocumentRoot /home/www/localhost/public_html
    ServerName myserver.net
    ErrorLog "|/usr/sbin/rotatelogs /home/www/localhost/logs/httpd/error_log.%m%d 86400 540"
    CustomLog "|/usr/sbin/rotatelogs /home/www/localhost/logs/httpd/access_log.%m%d 86400 540" combined env=!no_log
</VirtualHost>

同じ感じで他のバーチャルホストも設定します。
で、この設定を読み込んだり、バーチャルホストの設定を有効にするための設定をhttpd.confにします。

# vi /etc/httpd/conf/httpd.conf

#NameVirtualHost *:80
↓コメントアウト削除
NameVirtualHost *:80

Include vhosts/*.conf

これでApacheを起動・再起動してください。
起動でも再起動でも設定ファイルが間違っていないか確認してからするようにしましょう。

# /etc/init.d/httpd configtest
Syntax OK.
# /etc/init.d/httpd restart