Score:0

Variables for Apache

de flag

I am in the process of setting up an Apache web server to host a few hundred sites. The sites will be nearly identical in configuration with the exception of some site specific information (Server name, Document Root, Directory, Log path).

I was hoping to define variables in each site's conf file and then include a file with the site settings.

For example, I would like to have a config file called site1.conf that defines the following variables in some way and then calls an include file for a standard configuration.

Define subdomain site1
Include /etc/httpd/sitedefaults.conf

Then within sitedefaults.conf, have something like the following that uses the variables defined in site1.conf

<VirtualHost 10.10.10.10:80>
  ServerName $subdomain.example.com
  DocumentRoot /var/www/$subdomain/

  ServerAdmin [email protected]

  ErrorLog /var/log/httpd/$subdomain/error.log
  CustomLog /var/log/httpd/$subdomain/access.log combined

  <Directory "/var/www/$subdomain/docs">
    Options FollowSymLinks Multiviews
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Is something like this possible?

us flag
It is better to use configuration management system like Ansible / SaltStack / Chef / Puppet to manage the configuration files.
Beacon-MR avatar
de flag
I would like a solution which allows me to make a change in 1 place and it affects all sites. For instance, if I made a change to "Options" in the Directory section, I do not want to have to touch 500 conf files (or 500 instances of this Option).
us flag
Yes, that's exactly how the configuration management systems work. You write config file templates, and then run the management program to generate / change configuration files accordingly. As an additional benefit, you can re-create the whole system from scratch using the information in the configuration management system.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.