1

i have an issue. I have a VirtualHost for domain1.com on IP 1.2.3.4, but Apache reply to the request to the IP 1.2.3.4 ignoring the ServerName.

So, if i point domain2.com to 1.2.3.4 i see the content of /var/www/html/domain1.com and not the content of /var/www/html/default

What is wrong?

Listen 80
NameVirtualHost 1.2.3.4:80
<VirtualHost 1.2.3.4:80>
SSLEngine off
DocumentRoot /var/www/html/domain1.com
ServerName www.domain1.com:80
<Directory "/var/www/html/domain1.com">
allow from all
</Directory>
  LogLevel notice
UseCanonicalName on
</VirtualHost>

<VirtualHost _default_:80>
DocumentRoot /var/www/html/default
<Directory /var/www/html/default>
allow from all
</Directory>
</VirtualHost>
0

1 Answer 1

3

Your use of _default_ here will match IPs that have not been defined for another VirtualHost. This means that a request to 1.2.3.4:80 according to your config will use the first defined VirtualHost for www.domain1.com. Priority of VirtualHost are defined by their order in the config file.

To achieve the configuration you desire, move your default VirtualHost above the www.domain1.com one, and change its IP from _default_ to 1.2.3.4.

Further information on the specifics of this are listed in the Apache manual which you can find at this link.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .