0

同じサーバー IP アドレスに対して複数の A レコードがあります。

URL DNS 解像度。
goodurl.com 10.0.0.1
badurl1.com 10.0.0.1
badurl2.com 10.0.0.1

URL goodurl.com でのみ動作し、他の URL では動作しないように Apache2 を構成したいと考えています。

次のように、特定の URL「badurl1.com」で「アクセスが拒否されました」を与える方法を見つけました。

<VirtualHost *:80>
    ServerName badurl1.com
    DocumentRoot /var/www
    <Directory /var/www/>
            AllowOverride None
            Order deny,allow
            deny from all
    </Directory>
</VirtualHost>

同じことを行うためのよりエレガントで効率的な方法はありますか?

他の将来の不要な新しい A レコードがデフォルトで拒否されるように Apache を構成する方法はありますか?

あなたの助けを前もって感謝します

システム SO: Linux 2.6.32-5-amd64 x86_64 GNU/Linux
サーバーのバージョン: Apache/2.2.16 (Debian)
4

2 に答える 2

0

動的仮想ホストを使用する必要があります。基本的に、パス名には仮想ホスト サーバー名が含まれるため、パスが存在しない場合、サーバーは file not found を返します。

<VirtualHost 111.22.33.44>
    ServerName                 customer-1.example.com
    DocumentRoot        /www/hosts/customer-1.example.com/docs
    ScriptAlias  /cgi-bin/  /www/hosts/customer-1.example.com/cgi-bin
</VirtualHost>

<VirtualHost 111.22.33.44>
    ServerName                 customer-2.example.com
    DocumentRoot        /www/hosts/customer-2.example.com/docs
    ScriptAlias  /cgi-bin/  /www/hosts/customer-2.example.com/cgi-bin
</VirtualHost>

<VirtualHost 111.22.33.44>
    ServerName                 customer-N.example.com
    DocumentRoot        /www/hosts/customer-N.example.com/docs
    ScriptAlias  /cgi-bin/  /www/hosts/customer-N.example.com/cgi-bin
</VirtualHost>

になる

# get the server name from the Host: header
UseCanonicalName Off

# this log format can be split per-virtual-host based on the first field
# using the split-logfile utility.
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot /www/hosts/%0/docs
VirtualScriptAlias  /www/hosts/%0/cgi-bin

http://httpd.apache.org/docs/current/vhosts/mass.html

于 2015-03-05T15:39:22.127 に答える