有没有一种方法可以声明基于名称的虚拟主机,但共享相同的目录声明?例如,这两个 Vhost 中的目录部分是相同的,那么有没有一种方法可以只声明一次,并让两个 Vhost 都使用它?错误日志部分也是如此。有没有一种方法可以只声明一次错误日志?(可能在目录中?)
<VirtualHost *:80>
ServerName email.123456.com
DocumentRoot /var/www/mail
<Directory /var/www/mail>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mail/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/mail/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName email.123456.com
DocumentRoot /var/www/mail
<Directory /var/www/mail>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mail/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/mail/access.log combined
SSLEngine on
SSLCertificateFile /var/certs/123456/123456.com.crt
SSLCertificateKeyFile /var/certs/123456/123456.key
SSLCertificateChainFile /var/certs/123456/sf_bundle.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
BrowserMatch MSIE [17-9] ssl-unclean-shutdown
</VirtualHost>
</IfModule>
答案1
如果是我的话,我会将共享配置存储在“片段” .conf 文件中,并在每个 VirtualHost 或共享这些片段内配置的其他地方使用 Include 指令。即
Include conf-fragments/error-log.conf
Include conf-fragments/Directory-mail.conf