In Apache2 on ubuntu I have my site listening on 80, and now I want to add SSL. Is there a way to enable the SSLEngine for port 443 so I do not have to copy the entire VirtualHost block?
When I do this:
Listen 80
Listen 443
NameVirtualHost *
<VirtualHost *>
SSLEngine On
... a bunch more lines...
</VirtualHost>
It is turning on the SSLEngine for port 80. Is there a way to use only the one VirtualHost block, and only turn on the SSLEngine for port 443? So I can do something like this?
Listen 80
Listen 443
NameVirtualHost *
<VirtualHost *>
<IfPort 443>
SSLEngine On
</IfPort>
... a bunch of lines I don't want to copy into another VirutalHost block...
</VirtualHost>
Best Answer
You can't make one vhost do both HTTP and HTTPS, because they are separate vhosts servicing separate protocols. Instead, you should put all of the common configuration into a separate file, and then include that file in both the SSL and non-SSL vhosts for the domain.
Minimal example: