There are many virtual hosts in my apache configuration, each having quite a big amount of settings. The problem is that most of the virtual servers have the same settings. So config file is huge, full of identical virtual hosts, that differ only by ServerName directive. To change or add setting, I need to go through all of these vhosts.
Is it possible to somehow share settings between virtual hosts, but still having few of them with their own ones?
I hoped dynamic vhosts would be a good solution, but as I understand, it doesn't fit my problem, because there is no way to set specific settings for some of the vhosts. Furthermore I don't want my vhosts to be dynamic, because I have a fixed number of them. ServerAlias directive is also not a solution, because I need to know what url the user came from.

  • This seems like a relevant answer, albeit probably on the wrong stack exchange site.
    – Nate
    Dec 5, 2019 at 1:59

1 Answer 1


I have a similar situation to you and my solution was to write a (Perl) script that generates the vhost configs for me.

I have a configuration file which lists the few settings that are different per server (like ServerName, SSL certificate, etc) and then the Perl script combines the unique settings with generic ones and writes out many conf files in /etc/httpd/conf.d.

Then I include them all with something like this in the main config:

Include conf.d/*.conf

Every time I add a new vhost, I just add the data to the Perl script config file, run the script, then reload Apache.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .