Set up SSL cert for subdomain to work with https, Centos 7
The certificate doesn't have any influence on what the web server returns. Only the web server's virtual host configuration influences what the web server returns for each individual hostname.
In Apache, you must define two <VirtualHost>
blocks for each new subdomain, one for :80
and another for :443
, and both blocks must specify your domain as ServerName
. For example:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/example
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
DocumentRoot /home/example
SSLEngine On
SSLCertificateFile /etc/.../example.com.crt
SSLCertificateKeyFile /etc/.../example.com.key
</VirtualHost>
The web server will always use your browser's HTTP Host:
header to match against the virtual host's ServerName/ServerAlias
, regardless of certificate being served (e.g. even if you use the completely wrong certificate).
Note that the NameVirtualHost
option has been obsolete since Apache 2.4.0 (released in 2012) and is just ignored; in this version, all vhosts are name-based vhosts by default.
Similarly, Order
and Allow from
are both obsolete; they're replaced by Require all granted
in Apache 2.4, with the old versions still being handled by a compatibility module.