是否有可能写几个虚拟主机的共享configuration?

我的意图是避免了很多重复的代码。

基本上我想要做的是使用相同的SSLconfiguration块的几个VirtualHost条目…

<IfModule mod_ssl.c> <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> SSLCertificateFile /usr/share/ssl/certs/example/host.pem SSLCertificateKeyFile /usr/share/ssl/certs/example/host.key SSLCertificateChainFile /usr/share/ssl/certs/example/host.cert <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-6]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 # MSIE 7 and newer should be able to use keepalive BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown <VirtualHost 999.99.9.999:443> ServerName subdomain1.example.com DocumentRoot /var/www/subdomain1 </VirtualHost> <VirtualHost 999.99.9.999:443> ServerName subdomain2.bonfirehub.com DocumentRoot /var/www/subdomain2 </VirtualHost> </IfModule> 

现在这个configuration不适合我,但我想这说明了我想要实现的。 理想的下一步是将每个VirtualHost的通用configuration文件抽象为一个单独的文件,并通过Include指令加载。

如果不是,也许有人可以build议另一种configuration方法

我的目标是拥有一个共享的通用configuration,因为我打算添加几个VirtualHost条目给定的IP,只有DocumentRoot和ServerName不同。 特别是ServerName子域是唯一改变的(注意我使用通配证书),这就是为什么我要设置共享configuration。

我已经明白了这一点,但是如果别人觉得这个有用,我会留下来的。

 # VirtualHost <IfModule mod_ssl.c> <VirtualHost 999.99.9.999:443> ServerName subdomain1.example.com DocumentRoot /var/www/subdomain1 Include example.com-ssl.conf </VirtualHost> <VirtualHost 999.99.9.999:443> ServerName subdomain2.example.com DocumentRoot /var/www/subdomain2 Include example.com-ssl.conf </VirtualHost> </IfModule> # Shared Config File ServerAdmin webmaster@localhost <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory> # SSL Engine Switch: # Enable/Disable SSL for this virtual host. SSLEngine on # A self-signed (snakeoil) certificate can be created by installing # the ssl-cert package. See # /usr/share/doc/apache2.2-common/README.Debian.gz for more info. # If both key and certificate are stored in the same file, only the # SSLCertificateFile directive is needed. SSLCertificateFile /usr/share/ssl/certs/*.example.com/host.pem SSLCertificateKeyFile /usr/share/ssl/certs/*.example.com/host.key # Server Certificate Chain: # Point SSLCertificateChainFile at a file containing the # concatenation of PEM encoded CA certificates which form the # certificate chain for the server certificate. Alternatively # the referenced file can be the same as SSLCertificateFile # when the CA certificates are directly appended to the server # certificate for convinience. SSLCertificateChainFile /usr/share/ssl/certs/*.example.com/host.cert <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-6]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 # MSIE 7 and newer should be able to use keepalive BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown 

我意识到,我最初的configuration块在顶部是缺less一些代码。 我唯一的跟进问题是,而不是写

 Include example.com-ssl.conf 

在每个VirtualHost中都没有办法让它们都包含这个文件?