Do I have to duplicate the Virtualhost directives for port 80 and 443? Do I have to duplicate the Virtualhost directives for port 80 and 443? apache apache

Do I have to duplicate the Virtualhost directives for port 80 and 443?


Can't you use an include directive to include the common rules. here

article

eg.:

<VirtualHost _default_:80>    ...    include conf/common_rule.conf</VirtualHost><VirtualHost _default_:*>    ...    include conf/common_rule.conf</VirtualHost> <VirtualHost _default_:443>    ... #SSL rules    include conf/common_rule.conf</VirtualHost>  


You can use any # of hosts and ports in a single Virtualhost directive.

<VirtualHost addr[:port] [addr[:port]] ...> ... </VirtualHost> 

In My case I used.

<VirtualHost *:80 *:443>  ServerName loop.lk ....SSLEngine onSSLCertificateFile /etc/apache2/ssl/local.crt</VirtualHost>


Sorry to bump up an old post like this, but in order to help other Googlers out there I wanted to share how I dealt with it:

I have a couple of vhosts on my localhost, say: localhost, foo.com, bar.com

This being a localhost site on my laptop (macosx) I could get away with self-signed certificates and thus the ssl-part is the same for all the vhosts...

What I did is this:

I created the directory /etc/apache2/extra/vhosts/.

I created a /etc/apache2/extra/vhosts/localhost.conf:

ServerName localhostDocumentRoot "/www/localhost"<Directory /www/localhost>  Require all granted</Directory>ErrorLog "/var/log/apache2/localhost.error_log"CustomLog "/var/log/apache2/localhost.access_log" common

A /etc/apache2/extra/vhosts/foo.conf:

ServerName foo.comDocumentRoot "/www/foo.com"<Directory /www/foo.com>  Require all granted</Directory>ErrorLog "/var/log/apache2/foo.com.error_log"CustomLog "/var/log/apache2/foo.com.access_log" common

A /etc/apache2/extra/vhosts/bar.conf:

ServerName bar.comDocumentRoot "/www/bar.com"<Directory /www/bar.com>  Require all granted</Directory>ErrorLog "/var/log/apache2/bar.com.error_log"CustomLog "/var/log/apache2/bar.com.access_log" common

And finally a /etc/apache2/extra/vhosts/ssl.conf:

SSLEngine onSSLCertificateFile "/etc/apache2/ssl/server.crt"SSLCertificateKeyFile "/etc/apache2/ssl/server.key"

And in my /etc/apache2/extra/httpd-vhosts.conf:

<VirtualHost *:80>  Include /etc/apache2/extra/vhosts/localhost.conf</VirtualHost><VirtualHost *:443>  Include /etc/apache2/extra/vhosts/localhost.conf  Include /etc/apache2/extra/vhosts/ssl.conf</VirtualHost><VirtualHost *:80>  Include /etc/apache2/extra/vhosts/foo.conf</VirtualHost><VirtualHost *:443>  Include /etc/apache2/extra/vhosts/foo.conf  Include /etc/apache2/extra/vhosts/ssl.conf</VirtualHost><VirtualHost *:80>  Include /etc/apache2/extra/vhosts/bar.conf</VirtualHost><VirtualHost *:443>  Include /etc/apache2/extra/vhosts/bar.conf  Include /etc/apache2/extra/vhosts/ssl.conf</VirtualHost>