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'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>
...
</VirtualHost>

and

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

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
add comment

1 Answer

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> 

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

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

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.