Ssl – Change the default apache configuration to serve HTTPS on two ports

Apache2httpssslvirtualhost

I'm running apache2 on Devuan Beowulf (~= Debian Buster), with the default configuration. In that configuration, I have:

in sites-available/default-ssl.conf:

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
        # etc etc.

in sites-available/default-000.conf:

<VirtualHost *:80>
        # etc etc.

and in sites-available/default-000.conf:

Listen 80

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

How do I make it so that apache listens on port 80 for HTTP traffic and on ports 443 and, say, 1234, for HTTPS connections?

Best Answer

There are several tasks here:

  1. Make sure the SSL module is loaded
  2. Listen on another port for SSL - port 1234 specifically
  3. Make sure the default-ssl.conf site is enabled (or whatever site conf you want to use for your HTTPS site)
  4. Make the port-443 virtual host also be served for the second port - without simply copying that block of configuration

Here's how to do it (as root):

  1. Invoke a2enmod ssl (yes, there is such a utility)
  2. Add Listen 1234 right below Listen 443 in ports.conf
  3. Invoke a2ensite default-ssl
  4. Change <VirtualHost _default_:443> to <VirtualHost _default_:443 _default_:1234> in default-ssl.conf.

There's (at least) one problem with the above solution, though - somehow, magically, you can speak HTTP to the server on port 443.

Note: Don't insert NameVirtualHost lines; if you do, you'll get warnings saying:

AH00548: NameVirtualHost has no effect and will be removed in the next 
release /etc/apache2/ports.conf:6