LoginSignup
75
88

More than 5 years have passed since last update.

AWSのApache2.4の初期設定とセキュリティ設定

Last updated at Posted at 2015-05-15

 最初にする設定 httpd.conf, welcome.conf

設定が無い物は追記して、既存にあるものは変更する。又はコメントアウトして無効化する。

  • ServerAdminにemailを設定する。
  • ServerNameを設定する。
  • クロスサイトトレーシング対策(Basic認証のパスが漏れないようにする。)
  • トップページにディレクトリ一覧が表示する事を防ぐ
  • CGI を使ってない場合は、/cgi-bin/のエイリアス設定を無効にする。設定をコメントアウトする
  • SSI(サーバサイドインクルード)の使用を無効にする(デフォルトで無効なので特に記述追加は無し)
httpd.conf

# 変更 サーバー管理者への問い合わせ先メールアドレスに変更する
ServerAdmin webmaster@example.jp

# 変更 ドメインと合わせる。
ServerName hogehoge@example.com:80

# 追加 クロスサイトトレーシング対策 TRACE無効化
TraceEnable Off 

<Directory "/var/www/html">

    # 変更 -Indexesとしてトップページにディレクトリ一覧が表示する事を防ぐ
    Options -Indexes FollowSymLinks

・・・省略・・・

# コメントアウト cgi-binを使用しない
#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" 

#<Directory "/var/www/cgi-bin">
#    AllowOverride None
#    Options None
#    Order allow,deny
#    Allow from all
#</Directory>
  • アパッチのトップページ(テストページ)を非表示にする。welcome.confの中身をコメントアウト
conf.d/welcome.conf

# コメントアウト テストページを非表示にする
#<LocationMatch "^/+$">
#    Options -Indexes
#    ErrorDocument 403 /error/noindex.html
#</LocationMatch>

共通セキュリティ security.conf

  • レスポンスヘッダ Server Apache/2.4.12 (Amazon)とかfullで出さない。
  • レスポンスヘッダ X-Powered-By PHP/5.3.29とか出さない。
  • 脆弱性のあるsslプロトコルのsslv3を無効にする。
  • .htaccessを許可したいディレクトリは個別に設定する。
  • v2.4はデフォルトでServerSignature Off
conf.d/security.conf

# Hide Apache Version
ServerTokens Prod

# Hide Header X-Powered-By
Header always unset X-Powered-By

# Anti POODLE
SSLProtocol All -SSLv3

# .htaccessファイルを許可するディレクトリを個別に指定します。
<Directory /var/www/html/hogehoge>

AllowOverride All
</Directory>

AWS ロードバランサーにぶら下がっている場合 aws_elb.conf

  • 408ログがELBから多発する時の設定を入れる。 コネクションタイムアウトデフォルト60秒なので、RequestReadTimeout headerをそれより大きく設定する
  • アクセスログにELBのIPが出てしまうのでアクセス元のIPが表示されるログフォーマットを作成
conf.d/aws_elb.conf

# Set over AWS ELB connection time out default 60s
RequestReadTimeout header=70

# ELB access_log format
LogFormat "%h %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" elbcombined

最後に

自分の技術ブログではフリーランス界隈の情報や最新のIT情報の発信していますので、よろしくお願いします。

75
88
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
75
88