我当前的httpd.conf文件看起来像这样:
<VirtualHost *:443> DocumentRoot /var/www/html/www.example1.com ServerName www.example1.com SSLEngine on SSLCertificateFile /var/www/ssl/www.example1.com/certificate.crt SSLCertificateKeyFile /var/www/ssl/www.example1.com/private.key SSLCACertificateFile /var/www/ssl/www.example1.com/bundle.crt </VirtualHost> <VirtualHost *:443> DocumentRoot /var/www/html/www.example2.com ServerName www.example2.com SSLEngine on SSLCertificateFile /var/www/ssl/www.example2.com/certificate.crt SSLCertificateKeyFile /var/www/ssl/www.example2.com/private.key SSLCACertificateFile /var/www/ssl/www.example2.com/bundle.crt </VirtualHost>
我希望能够将“ServerName”存储在某种类型的变量中,以便能够简化文件(如下所示):
Define server_name = ServerName <VirtualHost *:443> DocumentRoot /var/www/html/${server_name} ServerName ${server_name} SSLEngine on SSLCertificateFile /var/www/ssl/${server_name}/certificate.crt SSLCertificateKeyFile /var/www/ssl/${server_name}/private.key SSLCACertificateFile /var/www/ssl/${server_name}/bundle.crt </VirtualHost>
解决方法
尝试
mod_macro
mod_macro
这是一个例子:
## 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