前のページ « | 1 | » 次のページ

Webサーバ(Apache)

2009, 02, 15

Apache はインターネットで最も普及しているオープンソースの Web サーバソフトウェアー。Apache は標準でインストールされているのでサーバーの設定に移る。

■Apache がインストールされてるかどうか確認する。
[root@server ~]# rpm -q httpd
httpd-2.2.3-11.el5_2.centos.4  ← パッケージ情報が表示された

パッケージ情報が表示されなければインストールする。
[root@linux ~]# yum -y install httpd 


■PHPをインストール
[root@linux ~]# yum -y install php


■Apacheの設定
Apacheの設定ファイルの編集
[root@linux ~]# vi /etc/httpd/conf/httpd.conf

エラーページ等でOS名を表示しないようにする
ServerTokens OS
             ↓
ServerTokens Prod

エラーページ等でApacheのバージョンを表示しないようにする
ServerSignature On
                ↓
ServerSignature Off

管理者のメールアドレスを設定する
ServerAdmin root@localhost
                  ↓
ServerAdmin webmaster@yokensaka.com ← 独自ドメインに変更

サーバー名を指定
#ServerName www.example.com:80
                  ↓
ServerName yokensaka.com:80 ← #をはずして独自ドメインに変更

CGIスクリプトを実行できる様にする
#AddHandler cgi-script .cgi
         ↓
AddHandler cgi-script .cgi .pl ← #をはずして.plを追加

デフォルトキャラセットを無効にする
AddDefaultCharset UTF-8
         ↓
#AddDefaultCharset UTF-8 ← #を付ける

CGIの許可、SSIの許可、シンボリックリンク許可
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks
         ↓
    Options Includes ExecCGI FollowSymLinks

.htaccessの許可
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None
         ↓
    AllowOverride All

長すぎるURI(414 Error)はログに記録しない
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
         ↓
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

ログの記録内容変更
# logged therein and *not* in this file.
#
#CustomLog logs/access_log common
この下に以下を追加
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no_log
SetEnvIf Remote_Addr 192.168. no_log
CustomLog logs/access_log combined env=!no_log


■Perlのパスが/usr/local/bin/perlでもCGIを実行出来るようにする。
現在のPerlの位置
[root@linux ~]# which perl
/usr/bin/perl

シンボリックリンク設定(/usr/local/bin/perlから/usr/bin/perlへリンクをはる)
[root@linux ~]# ln -s /usr/bin/perl /usr/local/bin/perl

変更後のPerlの位置
[root@linux ~]# which perl
/usr/local/bin/perl


■ドキュメントルートの所有者変更
[root@linux ~]# chown higo:higo /var/www/html/ ← ドキュメントルート所有者変更

[root@linux ~]# ll /var/www/ ← ドキュメントルート所有者変更確認
合計 32
drwxr-xr-x 2 root root 4096 2007-05-09 19:28 cgi-bin
drwxr-xr-x 3 root root 4096 2007-06-10 23:53 error
drwxr-xr-x 2 higo higo 4096 2007-05-09 19:28 html
drwxr-xr-x 3 root root 4096 2007-06-10 20:26 icons

※-Rオプションによりディレクトリの階層化にある全てのフォルダ、ファイルの所有者を変更できる。
[root@server ~]# chown -R higo /var/www/html/


■Apacheの起動
Apache(httpd)を起動する
[root@linux ~]# /etc/rc.d/init.d/httpd start
httpd を起動中:                                            [  OK  ]


■Apacheの自動起動設定
[root@linux ~]# chkconfig httpd on
[root@linux ~]# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
           ランレベル2〜5がオンの状態であることを確認


■Apacheの動作確認

http://192.168.1.2/ でアクセスして「Apache 2 Test Page」画面が表示されればOK。

■各機能の動作確認

1.テスト用のHTMLの表示確認を行う。

テスト用のhtmlを作成
[root@linux ~]# vi /var/www/html/index.html
<html>
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
     <title>テストページ</title>
     </head>
     <body>
     テストページ
     </body>
     </html>

http://192.168.1.2/index.html でアクセスして、「テストページ」と表示されればOK。

2.SSIの動作確認を行なう。
テスト用のshtmlを作成
[root@linux ~]# vi /var/www/html/index.shtml
<html>
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
     <title>テスト</title>
     <body>
     SSIテスト
     <!--#config timefmt="%Y/%m/%d %H:%M:%S" -->
     <!--#echo var="DATE_LOCAL" -->
     </body>
</html>

http://192.168.1.2/index.shtml でアクセスして、現在の日付が表示されればOK。

3.CGIの動作確認を行なう。
テスト用のcgiを作成
[root@linux ~]# vi /var/www/html/test.cgi
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-jp\">";
print "<title>テストページ</title>\n";
print "</head>\n";
print "<body>\n";
print "CGIテスト\n";
print "</body>\n";
print "</html>\n";

cgiのパーミッション変更
[root@linux ~]# chmod 755 /var/www/html/test.cgi

http://192.168.1.2/test.cgi でアクセスして、「CGIテスト」と表示されればOK。

4.PHPの動作確認を行なう。
テスト用のphpを作成
[root@linux ~]# vi /var/www/html/test.php
<?php
    phpinfo();
?>

http://192.168.1.2/test.php でアクセスして、PHPインフォメーション画面が表示されればOK。

■公開前の準備
ホームページを外部に公開するに当たって、ルータの設定でポート番号80番を開ける必要がある。

■ ポートチェック【ポート開放確認】
「管理しているサーバーが外部から接続アクセスできるか?」「ポートは開放されているか?」「portは閉じているか?」「ルータのポートは開放されているか」等の
ポートチェック・ポートの疎通確認テストはこちらで

前のページ « | 1 | » 次のページ