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.

Nathan C
  • 15,059
  • 4
  • 43
  • 62
anonymous-one
  • 1,018
  • 7
  • 27
  • 43

5 Answers5

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.

JamesHannah
  • 1,731
  • 2
  • 11
  • 24
1

Sure:

Listen 80

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

Alternatively, consider using name-based virtual hosts instead.

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
1

You could use...

Listen 80

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

..to bind to any IP on the server

Paul Willis
  • 316
  • 1
  • 6
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.

Mark Wagner
  • 18,019
  • 2
  • 32
  • 47
  • 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
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.

mdpc
  • 11,856
  • 28
  • 53
  • 67