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.

I currently just have one non-virtual host and my httpd.conf file is a regular run-of-the-mill file with ordinary modules and stuff. Now I have a need for another host yet it needs to be on the same server. I found apache virtual hosts and have a question about the setup of my config file.

Right now:

Listen 80
<IfModule> ........
.....
....

My question is, to keep the same settings for each virtual host do I have to copy my current file twice? One inside each virtual host tag? Like this:

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

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

I hope I'm explaining myself correctly.

share|improve this question
add comment

2 Answers 2

No. Those httpd.conf settings are global context (Listen) and scope (LoadModule) and you do not duplicate them in VirtualHosts.

Note that it's a bit more complicated with what can and cannot be set in VHs, and what is inherited.

See http://httpd.apache.org/docs/2.2/mod/quickreference.html for context.

share|improve this answer
add comment

As noted, most of your config file is global. You really just need to put in the virtual config, the bits that are different. There's really two key items:

The DocumentRoot, and ServerName. You might also have different log files, directory index, Aliases, etc. But the two key lines are as below.


    DocumentRoot /var/www/serverroot
    ServerName name.example.com

share|improve this answer
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.