How do I set up listening for https requests in apache2?

One of my virtual hosts has a form of:

    <VirtualHost *:80>
        ServerName central
        DocumentRoot /var/www4
        ...
    </VirtualHost>

How should I modify this extract of my virtual-host-config to enable apache to listen to https? I need it because my website is supposed to send https POST requests at login. I've tried changing the opening tag for:

    <VirtualHost *:80 *:443>

..., but it didn't work. Any ideas?

link|improve this question

68% accept rate
feedback

2 Answers

up vote 6 down vote accepted

try this

Listen 10.1.2.3:443
Listen 10.1.2.3:80

NameVirtualHost 10.1.2.3:443
<VirtualHost 10.1.2.3:443>
  ServerName some.name.com
  SSLEngine On
  SSLCertificateFile /path/to/file.crt
  SSLCertificateKeyFile /path/to/file.key
  DocumentRoot /var/www4/ssl
#   ....
</VirtualHost> 

<VirtualHost 10.1.2.3:80>
  DocumentRoot /var/www4/nossl/
#   ....
</VirtualHost>
link|improve this answer
feedback

The Listen directive is what you want, but be warned, you need to have a dedicated IP for a proper SSL implementation. Using VirtualHosts (your *:80 and *:443 use this) with ServerName and ServerAlias won't work because that information is gathered from data sent after establishing an encrypted connection (the Hostname part of HTTP 2 exchange is how it figures out your virtualhost).

If that doesn't make sense, I'll try to clarify.

link|improve this answer
2  
while it's not documented and not recommended and apache complains in the log files about it, it IS possible to use name-based vhosts with ssl - if and only if all the name-based ssl sites are subdomains of the same domain AND you have a wildcard certificate for that domain. you can even have both name-based and IP-based vhosts on the same apache server. – Craig Sanders Aug 6 '09 at 22:11
feedback

Your Answer

 
or
required, but never shown

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