LoginSignup
36
49

More than 5 years have passed since last update.

[Apache]指定した名前以外でのアクセスを制御する

Last updated at Posted at 2014-09-09

Apacheのバーチャルホストは指定した名前以外でアクセスされた場合、ひとつめに設定したバーチャルホストがデフォルトで使われます。なので自分が管理していないDNSとかで間違って自分のサーバーのIPアドレスを指定されたりするとその名前でアクセスが可能なんですね。
これを回避する方法をメモ。

正しいURLにリダイレクトする場合

以下をhttpd.confのはじめのバーチャルホストに書きます。
意図しない名前でのアクセスをすべて自分の管理する hogehoge.com にリダイレクトできます。

httpd.conf
<VirtualHost *:80>
    ServerName any
    Redirect / http://hogehoge.com/
</VirtualHost>

アクセス禁止にする場合

httpd.conf
<VirtualHost *:80>
    ServerName any
    <Location />
        Order Deny,Allow
        Deny from all
    </Location>
</VirtualHost>

デフォルトのテストページを無効にしておきます

/etc/httpd/conf.d/welcome.conf
<LocationMatch "^/+$">
#    Options -Indexes
#    ErrorDocument 403 /error/noindex.html
</LocationMatch>

参考URL

36
49
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
36
49