How can I set up apache2 (or nginx, possibly) to serve the same set of virtual hosts over both HTTP and HTTPS?
The certificate part is not the problem — all virtual hosts are inside one subdomain and I use a wildcard certificate for it.
I'm thinking of using proxypass for it, but, first, it seems slightly ineffective and, second, I'm not sure whether it would be secure (i.e. so that server cannot be asked over HTTPS for some irrelevant host); and I don't (yet) see how this can be set up in apache anyway.
EDIT: Duplication of configuration parts is undesirable, i.e. it is still a last-resort solution.
First configure apache to listen to both http and http ports using the
Listen
directive.Then, set your
NameVirtualHost
directive(s) and Virtual Hosts. Apache Docs on Virtual Host setupProbably what you will do is duplicate your VirtualHost sections like so:
Stick the Vhost config in an .inc file. and have
Note that you can't have server aliases with SSL, at least not very easily. You can work around this with wildcard certificates and/or multiple CN's
<VirtualHost *:80 *:443> will work syntactically (as would <VirtualHost *:*>).
I'm assuming from your comment about having a wild-card cert and everything you're serving being in subdomains that you know that SSL and name-based virtual hosts don't always mix well.
After all, I've configured it on nginx with
in each virtual host and common_listen.conf:
(which seems to require nginx 0.8.x) and
ssl_certificate
in base config.Using
listen 443 default ssl;
multiple times seems to be incorrect in nginx.Somewhat related questions are: nginx HTTPS serving with same config as HTTP, Does Nginx need a unique ip address for every site served over HTTPS like Apache? (though in my case SNI is unnecessary).