Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a site which allows for ssl and non-ssl browsing.

I've got two virtualhosts set up in Apache to handle the two scenarios, ie:

<VirtualHost *:80>


<IfModule mod_ssl.c>
<VirtualHost *:443>

Now, my annoyance is that the (rather large) configuration is duplicated in both the vhosts (the only difference being the added SSL parameters in the ssl-vhost), so when I want to change something, I need to do it in both. It also feels and looks sloppy.

Is there any way to merge the two configurations?

Many thanks.

share|improve this question
different ports, setting up certificates etc are the reasons you need to have separate virtual hosts in your config. – Hex Nov 22 '12 at 23:39
If you set cookies / use session management, it's very hard to make the SSL requests properly secure without a lot of additional code. – symcbean Nov 22 '12 at 23:41
up vote 4 down vote accepted

Yes, this is needed as mentioned by @Hex in his comment.

However, you can take a shortcut and use the Include directive to not have the common configuration redundant, like this:

<VirtualHost _default_:80>
    include conf/common_rule.conf

<VirtualHost _default_:443>
    ... #SSL rules
    include conf/common_rule.conf

Stolen from the pretty much similar question "Do I have to duplicate the Virtualhost directives for port 80 and 443?".

share|improve this answer

Your Answer


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.