ペチパーノート

WEB開発系Tipsブログです。

Apacheのテストページを非表示にする

先の記事でAWSLAMP環境を作成しました。
~AWSでLAMP環境を作る~ まとめ
 

実際にWEBサイトを運用する為には、他にやっておいたほうがいい設定がいくつかあります。
その中のひとつがこれです。

f:id:butterbull:20140619232124j:plain

 

http://{IPアドレス or ドメイン}
のようにドキュメントルート直下にアクセスすると表示されます。
index.htmlが存在する場合はそちらが表示されますが、
存在しない場合はこのようなテストページが表示されます。

できれば出したくないですよね。。
     

手順

Apacheの設定ファイルを更新

# vi /etc/httpd/conf.d/welcome.conf

     

#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
   Options -Indexes
    ErrorDocument 403 /error/noindex.html
</LocationMatch>

↓ このようにLocationの括りをすべてコメントアウトします

#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
#<LocationMatch "^/+$">
#   Options -Indexes
#    ErrorDocument 403 /error/noindex.html
#</LocationMatch>

Apache再起動

service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

     

再度、ブラウザからアクセスしてみます

f:id:butterbull:20140620002839j:plain

テストページは表示されませんでした!!
がファイルの一覧や、サーバ情報が丸見えです。。
これを回避する為、大元のApache設定ファイルを更新します。

# vi /etc/httpd/conf/httpd.conf

ファイル一覧を非表示に

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/html">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# 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

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/html">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# 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にハイフンを付ける

  Apache再起動

service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

       

再度アクセスしてみます。

f:id:butterbull:20140620002549j:plain

 

これでOKです。