Apacheをインストールして設定した

目次

  • 参考にしたページ
  • インストール
  • 不要モジュールの無効化はスキップ
  • Apacheを起動
  • 自動起動の設定

インストール

$ sudo yum -y install httpd

今回はこういうバージョンでした。

$ httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Feb 13 2012 22:31:42

初期設定

まず設定ファイルのバックアップをとります。

$ sudo cp /etc/httpd/conf/httpd.conf $HOME

僕はこのやり方でやったんですが、後で下のケースの方が良いなと思いました。

$ cd
$ mkdir backup
$ sudo cp /etc/httpd/conf/httpd.conf ./backup

では設定ファイルを編集します。

$ sudo vim /etc/httpd/conf/httpd.conf

変更した部分だけ挙げていきます。

Web サーバーにアクセスしたクライアントに返す情報を変更

44行目付近。
vimで指定行に移動する場合は、編集モードで『44G』と入力します。

#
# Don't give away too much information about all the subcomponents
# we are running.  Comment out this line if you don't mind remote sites
# finding out what major optional modules you are running
ServerTokens OS

『OS』となっているところを『Prod』と書き換えます。
理由をまるまる引用します。

初期状態では ServerTokens OS、つまり OS 情報を表示するようになっている。この情報が詳細なほど、攻撃者にサーバー構成のヒントを与えることになる。
Prod を指定すれば、HTTP のレスポンスヘッダには Server: Apache だけ返すようになるので、これを設定しておく。

http://akabeko.me/blog/2012/04/revps-04-apache/
オプション設定

331行目付近。

# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

『Indexes』の前にハイフンをつけます。

初期状態では Indexes が設定されている。そのため、アクセスされたディレクトリ内に DirectoryIndex で設定されたファイル ( index.htm と index.html ) が見つからない場合、ファイル一覧ページが自動生成される。
これはセキュリティ的によろしくない ( 構成情報を広く公開してしまう )

http://akabeko.me/blog/2012/04/revps-04-apache/
エラーページなどに出力されるサーバー情報を変更
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
ServerSignature On

『On』を『Off』に切り替えます。

設定の確認
$ sudo apachectl configtest
Syntax OK

不要モジュールの無効化はスキップ

ここは今回スキップしました。

Apacheを起動

Apacheを起動します。

$ sudo service httpd start

『OK』と表示されるはずです。
ブラウザに『http://IPアドレス』を打ち込んでみましょう。
テストページが表示されます。

自動起動の設定

OSが起動したときに、Apacheも自動起動するように設定します。

$ chkconfig --list httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off

現在はオフになっています。

『chkconfig』というコマンドで設定します。

$ sudo chkconfig httpd on
$ chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

参照ページの説明はまだ余り理解できなかった…

お疲れさまです!
次はbasic認証をログするつもりです。