Specifying multiple NameVirtualHosts in a VirtualHost configuration

Posted on

Specifying multiple NameVirtualHosts in a VirtualHost configuration – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, virtualhost, configuration, , .

My server is running Apache2 and the configuration contains several NameVirtualHost settings.

# Example
NameVirtualHost aaa.bbb.ccc.ddd:80
NameVirtualHost xxx.yyy.zzz.qqq:80
NameVirtualHost [aaaa:ssss:dddd:ffff:gggg:hhhh]:80

There are Listen settings for all of them.

At this moment in time I am keeping track of two or more <VirtualHost foo:80> for each site because I want to be able to control which sites can be accessed through specific IP addresses. One of the reasons for doing it this way is ownership of the IP addresses the sites are being served on.

Question: Is it possible to create a “bundle” NameVirtualHost which contains more than 1 NameVirtualHost but not all NameVirtualHosts at once? The idea and reason for asking this question is that if I can bundle multiple NameVirtualHosts into one, then I would not have to administer multiple <VirtualHost foo:80> configuration sets for each site.


Solution :

Yes, it’s just a matter of having multiple domains in ServerAlias directive.

You could have one definition:

<VirtualHost aaa.bb.ccc.d:80>
      ServerName primary.domain.tld
      ServerAlias another.domain.tld *.example.org whatever.bla.ble
      #... other confs
      VirtualDocumentRoot /var/www/htdocs/%0

This way you can have only one definition, but several domains being served with just one vhost definition.

Leave a Reply

Your email address will not be published. Required fields are marked *