HTTPサーバ
解説
今やPCだけでなく携帯などでも閲覧可能となり、
より利用の機会が広がったウェブサイトですが、
HTTPサーバ(Webサーバ)はこのウェブサイトを
公開するための機能を持っています。
ここで利用するApacheは世界のシェアの約70%を占めており、
現在最も普及しているHTTPサーバソフトウェアです。
Apacheはプログラム1つでいろいろな機能を実現しているのではなく、
HTTPサーバに必要な機能1つ1つをモジュールという個別の
プログラムの形で準備しており、必要なものを組み込むことで
いろいろな機能をユーザに提供します。
対応バージョン
httpd-2.2.0-5.1.2(Fedora Core 5標準)
apr-1.2.2-7.2(Fedora Core 5標準)
apr-util-1.2.2-4.2(Fedora Core 5標準)
apr-1.2.2-7.2(Fedora Core 5標準)
apr-util-1.2.2-4.2(Fedora Core 5標準)
インストール
DHCPサーバに必要なパッケージを3つインストールします。
DVDドライブにFedora Core 5のDVD-ROMをセットし、以下のコマンドを実行します。
# mount /media/cdrom
# cd /media/cdrom/Fedora/RPMS
# rpm -ihv apr-1.2.2-7.2.i386.rpm
準備中... ########################################### [100%]
1:apr ########################################### [100%]
# rpm -ihv apr-util-1.2.2-4.2.i386.rpm
準備中... ########################################### [100%]
1:apr-util ########################################### [100%]
# rpm -ihv httpd-2.2.0-5.1.2.i386.rpm
準備中... ########################################### [100%]
1:httpd ########################################### [100%]
# cd /
# umount /media/cdrom
# cd /media/cdrom/Fedora/RPMS
# rpm -ihv apr-1.2.2-7.2.i386.rpm
準備中... ########################################### [100%]
1:apr ########################################### [100%]
# rpm -ihv apr-util-1.2.2-4.2.i386.rpm
準備中... ########################################### [100%]
1:apr-util ########################################### [100%]
# rpm -ihv httpd-2.2.0-5.1.2.i386.rpm
準備中... ########################################### [100%]
1:httpd ########################################### [100%]
# cd /
# umount /media/cdrom
設定
ここではApacheの一般的な設定を行います。
基本的にはインストールしただけで何もしなくても動きます。
しかし、初期状態ではユーザに見せたくない情報まで見せてしまうような
設定になっているため、セキュリティ上あまり好ましくありません。
できるだけ不要な機能は利用しない設定とし、
HTTPサーバとしてのセキュリティを向上させます。
なお、一般的にCGIプログラムの利用はニーズが高いため、
公開用ディレクトリのどこへ配置しても実行可能な設定とします。
(1) HTTPサーバの設定
viエディタで設定ファイル(httpd.conf)を開き、設定を変更します。
# cd /etc/httpd/conf/
# vi httpd.conf
ファイル(/etc/httpd/conf/httpd.conf)# vi httpd.conf
※以下、該当箇所のみ変更※
ServerTokens OS
↓変更
ServerTokens Prod
ServerAdmin root@localhost
↓変更
ServerAdmin webmaster@ranonet.ne.jp
#ServerName www.example.com:80
↓変更
ServerName www.ranonet.ne.jp:80
※コメント行を除外して表示しています※
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
↓変更
<Directory "/var/www/html">
Options FollowSymLinks ExecCGI ←設定を変更
AllowOverride None
Order allow,deny
Allow from all
<Limit GET HEAD POST> ←この行を追加
Order allow,deny ←この行を追加
Allow from all ←この行を追加
</Limit> ←この行を追加
<LimitExcept GET HEAD POST> ←この行を追加
Order deny,allow ←この行を追加
Deny from all ←この行を追加
</LimitExcept> ←この行を追加
</Directory>
DirectoryIndex index.html index.html.var
↓変更
DirectoryIndex welcome.htm index.html index.htm index.cgi
ServerSignature On
↓変更
ServerSignature Off
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
↓変更
#Alias /icons/ "/var/www/icons/" ←#を付ける
# ←#を付ける
#<Directory "/var/www/icons"> ←#を付ける
# Options Indexes MultiViews ←#を付ける
# AllowOverride None ←#を付ける
# Order allow,deny ←#を付ける
# Allow from all ←#を付ける
#</Directory> ←#を付ける
<IfModule mod_dav_fs.c>
# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb
</IfModule>
↓変更
#<IfModule mod_dav_fs.c> ←#を付ける
# Location of the WebDAV lock database.
# DAVLockDB /var/lib/dav/lockdb ←#を付ける
#</IfModule> ←#を付ける
AddDefaultCharset UTF-8
↓変更
AddDefaultCharset off
#AddHandler cgi-script .cgi
↓変更
AddHandler cgi-script .cgi
ServerTokens OS
↓変更
ServerTokens Prod
ServerAdmin root@localhost
↓変更
ServerAdmin webmaster@ranonet.ne.jp
#ServerName www.example.com:80
↓変更
ServerName www.ranonet.ne.jp:80
※コメント行を除外して表示しています※
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
↓変更
<Directory "/var/www/html">
Options FollowSymLinks ExecCGI ←設定を変更
AllowOverride None
Order allow,deny
Allow from all
<Limit GET HEAD POST> ←この行を追加
Order allow,deny ←この行を追加
Allow from all ←この行を追加
</Limit> ←この行を追加
<LimitExcept GET HEAD POST> ←この行を追加
Order deny,allow ←この行を追加
Deny from all ←この行を追加
</LimitExcept> ←この行を追加
</Directory>
DirectoryIndex index.html index.html.var
↓変更
DirectoryIndex welcome.htm index.html index.htm index.cgi
ServerSignature On
↓変更
ServerSignature Off
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
↓変更
#Alias /icons/ "/var/www/icons/" ←#を付ける
# ←#を付ける
#<Directory "/var/www/icons"> ←#を付ける
# Options Indexes MultiViews ←#を付ける
# AllowOverride None ←#を付ける
# Order allow,deny ←#を付ける
# Allow from all ←#を付ける
#</Directory> ←#を付ける
<IfModule mod_dav_fs.c>
# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb
</IfModule>
↓変更
#<IfModule mod_dav_fs.c> ←#を付ける
# Location of the WebDAV lock database.
# DAVLockDB /var/lib/dav/lockdb ←#を付ける
#</IfModule> ←#を付ける
AddDefaultCharset UTF-8
↓変更
AddDefaultCharset off
#AddHandler cgi-script .cgi
↓変更
AddHandler cgi-script .cgi
(2) HTTPサーバの起動ランレベル変更
OSの起動に併せてデーモンを自動起動する設定に変更します。
# chkconfig httpd on
以上で設定が終了しましたのでrcスクリプトを使用してデーモンを起動します。
# /etc/rc.d/init.d/httpd start
httpd を起動中: [ OK ]
httpd を起動中: [ OK ]
