Use the ServerName as a variable in httpd.conf file

Solution 1:

try mod_macro

Here is an example:

## Define a VHost Macro for repetitive configurations

<Macro VHost $host $port $dir>
  Listen $port
  <VirtualHost *:$port>

   ServerName $host
   DocumentRoot $dir

   # Public document root
   <Directory $dir>
       Require all granted
   </Directory>

   # limit access to intranet subdir.
   <Directory $dir/intranet>
     Require ip 10.0.0.0/8
   </Directory>
  </VirtualHost>
</Macro>

## Use of VHost with different arguments.

Use VHost www.apache.org 80 /vhosts/apache/htdocs
Use VHost example.org 8080 /vhosts/example/htdocs
Use VHost www.example.fr 1234 /vhosts/example.fr/htdocs