2

I have a server (Ubuntu 14.04) where I host several websites.

I have added the following Apache2 configuration files in /etc/sites-available; and I have enabled those sites (symlink to /etc/sites-enabled):

www.domain1.com.conf

<VirtualHost *:80>
    ServerName www.domain1.com
    ServerAlias domain1.com
    DocumentRoot /var/www/domain1.com/www/
</VirtualHost>

www.domain2.com.conf

<VirtualHost *:80>
    ServerName www.domain2.com
    ServerAlias domain2.com
    DocumentRoot /var/www/domain2.com/www/
</VirtualHost>

etc.

However, when I point my browser directly to the IP of the server, Apache2 seems to match the first virtual host file included (ie www.domain1.com.conf).

Is there any way to disable this, or alternatively how would a 000-default.conf file (which would be loaded first) look like to force apache to close the HTTP connection without returning any data?

1

You can use _default_ vhosts:

<VirtualHost _default_:*>
DocumentRoot /www/default
</VirtualHost>

More here: http://httpd.apache.org/docs/2.0/vhosts/examples.html#default

  • This needs to be the first vHost referenced in the configuration – roaima Feb 12 '15 at 12:31
0

Specify a VirtualHost that matches the IP address exactly, E.G.,

<VirtualHost 10.50.60.70:80>
    RedirectMatch 204 .*
</VirtualHost>
  • This sort of did the trick (except there is a syntax error as Redirect takes 2 or 3 arguments). I ended up using "RedirectMatch 204 (.*)" – quentinadam Feb 12 '15 at 12:32
  • Sorry, I haven't dealt with Apache in ages. Edited. – Mark R. Feb 12 '15 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.