Technology

Configuring Apache to use mod_vhost_alias

Posted by Pixafy Team

In a previous post, I talked about an Apache module called mod_vhost_alias and the benefits it could have.  A commenter posed a question:

Would you mind posting a full example of the vhost that you’re using for context? Additionally, what settings are you using in httpd.conf for things like DocumentRoot, ServerName, etc.

Here is the minimum configuration you would need to include in your httpd.conf file to get vhost aliasing to work.

You do not need to set ServerName because UseCanonicalName is set to Off.  The domain is grabbed from the request instead of the ServerName setting.  This is what we want for the aliasing to work.  Also, DocumentRoot is not used because we are using vhost alias to set the dynamic document root.

##################################################

ServerRoot "c:/wamp/bin/apache/apache2.2.22"

Listen 80

LoadModule dir_module modules/mod_dir.so LoadModule vhost_alias_module modules/mod_vhost_alias.so

ServerAdmin admin@localhost

UseCanonicalName Off

VirtualDocumentRoot c:/tariq/www/%0

##################################################

This does not include the configuration necessary for PHP, but using this you should be able to setup your own server.

If you want to add access control, you can always enable authz and add a Directory directive as such:

##################################################

LoadModule authz_host_module modules/mod_authz_host.so

<Directory "c:/tariq/www">

    Order deny,allow

    deny from all

    allow from 127.0.0.1

</Directory>

##################################################

Happy coding!

Leave us a comment below or tweet us @Pixafy!

Tags