[Fedora 9] Web Server

31 05 2008

Apache là phần mềm nguồn mở phổ cập nhất cho Web Server. Cài đặt và thiết lập nó như sau:

1. Kiểm tra xem apache đã được cài chưa:

[root@server ~]# rpm -q httpd
httpd-2.2.8-3.i386  ← パッケージ情報が表示された

パッケージ情報が表示されなければインストールします。
[root@linux ~]# yum -y install httpd
 
2. Cài đặt PHP
[root@linux ~]# yum -y install php


3. Thiết lập apache

Apacheの設定ファイルの編集
[root@linux root]# 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

4. Thiết lập path của Perl
現在の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

5. Đổ quyên cho DocumentRoot
[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

6. Khởi động Apache
Apache(httpd)を起動する
[root@linux ~]# /etc/rc.d/init.d/httpd start
httpd を起動中: [ OK ]

7. Thiết lập apache khởi động tự động
[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がオンの状態であることを確認

8. Test
8.1 Test với file html
テスト用のhtmlを作成
[root@linux ~]# vi /var/www/html/index.html

テストページ

テストページ

8.2 Xác nhận SSI có hoạt động hay ko
テスト用のshtmlを作成
[root@linux ~]# vi /var/www/html/index.shtml

テスト

SSIテスト


8.3 Xác nhận CGI
テスト用のcgiを作成
[root@linux ~]# vi /var/www/html/test.cgi
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "\n";
print "\n";
print "";
print "テストページ\n";
print "\n";
print "\n";
print "CGIテスト\n";
print "\n";
print "\n";

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

8.4 Xác nhận PHP
テスト用のphpを作成
[root@linux ~]# vi /var/www/html/test.php
phpinfo();
?>

Link tham khảo gốc