Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have a couple of complex virtual host definitions in our httpd.conf file.

What I mean by that is:

<VirtualHost .....>
....
</VirtualHost>

What I mean by complex is that they are full of rewrite rules and such.

We would like to bind this virtual host on 2 ip addresses. Currently it is bound only to one.

Is it possible to bind a virtual host to 2 ip addresses using a single VirtualHost?

It would make things a lot easier to have a single one if we need to make changes in the future.

share|improve this question
add comment

5 Answers 5

up vote 1 down vote accepted

An easy way to handle this is to extract the common bits into a separate file (e.g., /path/to/foo) and then Include it in your vhost defs:

<Vitrualhost ...>
  ServerName X
  DocumentRoot Y
  Include /path/to/foo
</Virtualhost>

<Vitrualhost ...>
  ServerName Z
  DocumentRoot A
  Include /path/to/foo
</Virtualhost>

Note: Do not put /path/to/foo somewhere that will be pulled in by a wildcard Include elsewhere.

share|improve this answer
    
we like this approach the best. keeps us from having to muck around with anames and such and keep the solution in apache's world. thanks! –  anonymous-one Oct 26 '11 at 20:22
add comment

You can just place multiple IP/Port specifiers in the definition, as described in the documentation.

Example:

<VirtualHost 1.2.3.4:80 2.3.4.5:80 1.2.3.4:8080>
DocumentRoot /path/to/wherever
ServerName example.com
# Stuff goes here
</VirtualHost>

Just make sure you've got Apache configured with enough NameVirtualHost definitions.

share|improve this answer
add comment

You could use...

Listen 80

<VirtualHost *:80>
...
</VirtualHost>

..to bind to any IP on the server

share|improve this answer
add comment

I would probably go with the named virtual hosts, AND make the modification to the DNS so that both IPs have A records with the same hostname.

share|improve this answer
add comment

Sure:

Listen 80

<VirtualHost _default_:80>
    ...
</VirtualHost>

Alternatively, consider using name-based virtual hosts instead.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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