linux – 使用ServerName作为httpd.conf文件中的变量

前端之家收集整理的这篇文章主要介绍了linux – 使用ServerName作为httpd.conf文件中的变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我当前的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

这是一个例子:

## 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

猜你在找的Linux相关文章