Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a method for declaring name based virtual hosts, but sharing the same directory declarations? So for example, the Directory section in both of these Vhosts is the same, so is there a method to only declare it once, and have it used by both Vhosts? Same for the Error log section. Is there a method for declaring the error log only once? (Possibly inside the Directory?)

<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>
share|improve this question

1 Answer 1

up vote 4 down vote accepted

If it were me, I'd store the shared configurations in "fragment" .conf files and use the Include directive in each VirtualHost or other place that shares the configurations within those fragments. i.e.

Include conf-fragments/error-log.conf
Include conf-fragments/Directory-mail.conf
share|improve this answer
    
I was wanting to keep them in the same file, but I can see some advantages (in reducing redundancy mainly), so I will give this a try. Thanks! –  BayssMekanique Feb 22 '13 at 19:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.