セキュリティに気を使いながらApacheをソースからビルド

男ならゴリゴリっと何でもソースからビルドできなきゃ!ということで
Apacheをソースからビルド。
オライリー本のこちらを参考に。

Apacheセキュリティ

Apacheセキュリティ

1.OSのバージョンを確認

cat /etc/redhat-release

2.コンパイラーのバージョンを確認

gcc --version

3.インストールされていなかったのでインストール

yum -y install gcc gcc-c++

4.yumで入っていたapacheをアンインストール

yum remove httpd

5.インストールするApacheのソースをダウンロード

cd /usr/local/src/
wget http://www.meisei-u.ac.jp/mirror/apache/dist//httpd/httpd-2.2.19.tar.gz

6.sumチェック

sha1sum httpd-2.2.19.tar.gz 

7.コンパイルでオプションを指定しつつインストール

cd httpd-2.2.19
./configure --prefix=/usr/local/apache --disable-info --disable-status --disable-userdir --enable-rewrite --enable-headers --enable-setenvif
make
make install

8.起動確認

/usr/local/apache/bin/apachectl start
ps aux | grep httpd

9.ブート時の自動機同設定

cd /etc/rc3.d/
ln -s /usr/local/apache/bin/apachectl S85httpd
chown -R root:root /usr/local/apache
chmod -R go-w /usr/local/apache
chmod -R go-r /usr/local/apache/conf/
chmod -R go-r /usr/local/apache/logs/

vim /usr/local/apache/bin/apachectl
# chkconfig: - 85 15  
# description: Apache is a World Wide Web server.  It is used to serve \ 
#              HTML files and CGI. 
# processname: httpd 

chkconfig --add httpd
chkconfig httpd on


10.LAMP環境を想定していたので/usr/local/apache/conf/httpd.confのDirectoryIndexにindex.phpを追加

vim /usr/local/apache/conf/httpd.conf
    <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>
    Include conf.d/*.conf

不要なモジュール、設定を省くなど、セキュリティーを高めるためにできることはいくらでもあるのだけれど
ガチガチやろうとするとかなり労力が保守するたびにかかってくるので
コストを意識しながら落とし所を付けて作業しないと。