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.

My httpd-vhosts.conf file looks like this:

<VirtualHost *:80>
DocumentRoot "/www/foo/htdocs"
ServerName foo
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/www/bar/htdocs"
ServerName bar
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/www/baz/htdocs"
ServerName baz
</VirtualHost>

Notice the pattern? Is there any way to cut down on the duplication, or am I stuck with having a separate VirtualHost entry for each site?

share|improve this question
    
duplicate of serverfault.com/questions/6920/… –  vartec May 12 '09 at 10:41
add comment

3 Answers 3

I suggest you have a look at the Apache website for dynamic virtual hosts. The other methods require a restart of the Apache server.

http://httpd.apache.org/docs/2.0/vhosts/mass.html

share|improve this answer
add comment
up vote 1 down vote accepted

I figured out how to do it after reading Dark Ninja's answer. Here's what my httpd-vhosts.conf file looks like now.

# Dynamic virtual hosts.
# See http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html
UseCanonicalName Off
VirtualDocumentRoot /www/%0/htdocs/

I also had to enable mod_vhost_alias by uncommenting this line in httpd.conf

LoadModule vhost_alias_module modules/mod_vhost_alias.so
share|improve this answer
add comment

There are two very different answers.

  1. Use the "subdomain-as-account-folder"trick.
  2. Write a short script and configuration file that together generate your httpd-vhosts.conf file(s) dynamically. Then the script and configuration become your masters, and the .conf files are "expendable."

I recommend #2, and I think the Pragmatic Programmers might as well.

share|improve this answer
1  
I think #2 will require restarting httpd service though? –  mr1031011 Oct 30 '13 at 16:13
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.