I was configuring a pair of domains that shared the same SSL certificate, that the content will be in different folders and evidently that everything was on the same server.
My domains are:
example.com (For the Website)
api.example.com (For the Web Service)
I got the SSL Certificate with Let's Encrypt (free) .
The certificate was generated for both domains, therefore it could be placed in the same directory.
/etc/apache2/ssl/example.com /
Later I made the respective settings in the Apache sites directory.
/ etc / apache2 / sites-available /
Likewise, perform the activation of the sites:
a2ensite example.com
a2ensite api.example.com
The structure of the website is:
-> /var/www/
-> website/
-> api/
These are the configurations:
/etc/apache2/sites-available/example.com
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/website/
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/example.com/error.log
<Directory "/var/www/website/">
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/website/
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/example.com/error_ssl.log
SSLEngine on
SSLCertificateKeyFile /etc/apache2/ssl/example.com/privkey.pem
SSLCertificateFile /etc/apache2/ssl/example.com/cert.pem
SSLCertificateChainFile /etc/apache2/ssl/example.com/chain.pem
<Directory "/var/www/website/">
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
/etc/apache2/sites-available/api.example.com
<VirtualHost *:80>
ServerName api.example.com
DocumentRoot /var/www/api/
#RewriteEngine On
#RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
<Directory "/var/www/api/">
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName api.example.com
DocumentRoot /var/www/api/
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
SSLEngine on
SSLCertificateKeyFile /etc/apache2/ssl/example.com/privkey.pem
SSLCertificateFile /etc/apache2/ssl/example.com/cert.pem
SSLCertificateChainFile /etc/apache2/ssl/example.com/chain.pem
<Directory "/var/www/api/">
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
The drawback is:
When I access the example.com
site in the browser, the content that has api.example.com
is opened.
This gives rise to my question: