4

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.

5 Answers 5

1

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.

1
  • 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! Oct 26, 2011 at 20:22
3

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.

1

Sure:

Listen 80

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

Alternatively, consider using name-based virtual hosts instead.

1

You could use...

Listen 80

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

..to bind to any IP on the server

0

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.

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.