Webサーバーの構築

■概要
Apache (Webサーバー)
■使用するパッケージがインストールされているかの確認
# rpm -q httpd
httpd-2.0.54-10
■設定
Apache (Webサーバー)
(1) root権限に切り替え
[d1@localhost ~]$ su -
Password:
(2) Apacheの起動
[root@localhost ~]# /etc/rc.d/init.d/httpd start
httpd を起動中:                                            [  OK  ]
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
(3) Apacheの設定
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf
1. DocumentRoot の設定。
Before
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
After
<Directory "/var/www/html">
    Options -Indexes FollowSymLinks ← 自動インデックス生成をしない
    AllowOverride AuthConfig Limit ← 認証とIP制限のみ.htaccessで許可
    Order allow,deny
    Allow from all
</Directory>
2. LanguagePriority の設定。
Before
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko...長いので省略
After
LanguagePriority ja en ca cs da de el eo es et fr he hr it ko...← ja を先頭に移動
3. AddDefaultCharset ディレクティブの設定。
Before
AddDefaultCharset UTF-8
After
#AddDefaultCharset UTF-8 ← コメント化する
4. ServerTokens ディレクティブの設定。
Before
ServerTokens OS
After
ServerTokens ProductOnly ← 名前だけにする Apache
or
ServerTokens Minor ← Apache/2.0
5. ServerSignature ディレクティブの設定。
Before
ServerSignature On
After
ServerSignature Off ← Offにする
6. icons ディレクトリの設定。
Before
<Directory "/var/www/icons">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
After
<Directory "/var/www/icons">
    Options -Indexes MultiViews ← 自動インデックス生成をしない
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
(4) 不要なディレクトリやファイルの削除
[root@localhost ~]# rm -f /var/www/error/noindex.html
[root@localhost ~]# rm -f /etc/httpd/conf.d/welcome.conf

マニュアルの削除
# rm -fr /var/www/manual
# rm -fr /etc/httpd/conf.d/manual.conf
(5) php.iniの編集。マルチバイトセッションを有効にする。
[root@localhost ~]# vi /etc/php.ini
Before
[mbstring]
;mbstring.language = Japanese
;mbstring.internal_encoding = EUC-JP
;mbstring.http_input = auto
;mbstring.http_output = SJIS
;mbstring.encoding_translation = Off
;mbstring.detect_order = auto
;mbstring.substitute_character = none;
;mbstring.func_overload = 0
After
[mbstring]
; デフォルトの言語を設定
mbstring.language = Japanese
; デフォルトの内部エンコーディングを設定
mbstring.internal_encoding = EUC-JP ← 自分の環境に合わせる
; デフォルトのHTTP入力文字エンコーディングを設定
mbstring.http_input = auto
; デフォルトのHTTP出力文字エンコーディングを設定
mbstring.http_output = SJIS ← 自分の環境に合わせる
; HTTP入力エンコーディング変換の設定
mbstring.encoding_translation = Off
; デフォルトの文字エンコーディング検出順序を設定
mbstring.detect_order = auto ← たまにこれで悩まされるので要注意
; 代替文字のデフォルト値を設定
mbstring.substitute_character = none;
; マルチバイト対応版関数による既存関数のオーバーロード
mbstring.func_overload = 0 ← この設定はなるべく扱わないで、スクリプト側で設定すること
(6) 公開ディレクトリの設定。
[root@localhost ~]# cd /var/www/html
ここが公開されるところ。適当になんか作る。
[root@localhost ~]# /var/www/html
memo

mrtg       …  サーバ状態モニタ
webalizer  …  アクセス解析

manual     …  Apache マニュアル
htdig      …  WWW Search Engine Software
wordtrans  …  PHPによる単語翻訳

TFTP

192.168.0.
192.168.0.0/24
192.168.0.0/255.255.255.0

MPM (Multi Processing Module)
prefork
worker
perchild

SSLRequireSSL

Options SymLinksIfOwnerMatch

「編集(E)」
↓
「設定(N)」
↓
「動作」タブ
「常にブラウザ・ウインドウで開く(B)」チェック

Alias /usage /var/www/usage


    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    Allow from ::1
    # Allow from .example.com


↓

Alias /usage /var/www/usage


    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    Allow from ::1
    # Allow from .example.com
    Allow from 192.168.1.


ログのローテート
/etc/cron.daily
logrotate

/etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

1個のログ・ファイルに1週間分のログが記憶され、過去のログも4週間分保存される。

Apache のログに関する設定
/etc/logrotate.d/httpd

/var/log/httpd
〜logで終わるファイル
logrotateによってローテートされる

/etc/cron.daily
00webalizer
自動実行

/etc/webalizer.conf
カスタム

# tail -f /var/log/httpd/access_log

telnet localhost 25