0

I am building a system and I need to use the same IP and same folder for a site with multiple domains and a seperate SSL certificate for each one. Also I do not want them to redirect or forward, because the site can handle the different domains on its own.

so like

site1.example.com 192.168.0.2:443 /var/www/html

site2.example.com 192.168.0.2:443 /var/www/html

site3.example.com 192.168.0.2:443 /var/www/html

site4.example.com 192.168.0.2:443 /var/www/html

I am using Ubuntu 14.04 with Apache2 I really have no idea on how the hosts file should look for this, can someone show me an example?

5
  • Yes, it works. You can have either a certificate for each domain, or one single certificate for all domains with the domains as subject alternate names in the certificate, or one single certificate for *.domain.com.
    – AlexP
    Jan 12, 2017 at 17:29
  • how would my vhost file look for this? Jan 12, 2017 at 17:46
  • Depends on whether you choose to have a different certificate for each domain, or one single certificate for all domains. Pick one choice and edit the question.
    – AlexP
    Jan 12, 2017 at 17:53
  • Can anyone help with how to setup the vhost for this setup? Jan 16, 2017 at 19:27
  • I am using Apache 2 on ubuntu 14.04lts Jan 16, 2017 at 20:33

2 Answers 2

1

Earlier it was painful to multiple SSL certificate on multiple sites hosted on single IP address. Due to this website administrators need to invest more money to purchase individual IP addresses. However now with the help of SNI (Server Name Indicator) it is possible to protect multiple sites with different SSL Certificates on single Internet Protocol on Apache.

Set up SNI with Apache:

First take a fresh backup of your .conf

Now to achieve above mentioned functionalities, you need to create Virtual Host on your server. Create new .conf file for new Virtual Host or you can use existing. If you are creating a new .conf file you need to add following line into existing .conf file.

Include my_other_site.conf

Now list your public IP addresses in the NameVirtualHost directive by using port *:443. Afterwards you need to point Root Certificate, Intermediate Certificate, and SSL File to the each websites. Check below example for more:

NameVirtualHost *:443

<VirtualHost *:443>
 ServerName site1.domain.com 
 DocumentRoot /var/www/site
 SSLEngine on
 SSLCertificateFile /path/to/site1_domain_com.crt
 SSLCertificateKeyFile /path/to/site1_domain_com.key
 SSLCertificateChainFile /path/to/CA.crt
</VirtualHost>

<VirtualHost *:443>
 ServerName site2.domain.com
 DocumentRoot /var/www/site2
 SSLEngine on
 SSLCertificateFile /path/to/site2_domain_com.crt
 SSLCertificateKeyFile /path/to/site2_domain_com.key
 SSLCertificateChainFile /path/to/CA.crt
</VirtualHost>

This should work properly but in my opinion, you should not use different SSL Certificates fro different sites when you can get single SAN (Subject Alternative Names) SSL as you can secure multiple sites with single certificate. And if you have only sub-domains to secure under the one domain then you can simply opt Wildcard SSL, which can be cost effective option. You just need to issue Wildcard certificate as *.domain.com and everything (only first level) in place of asterisk (*) will be covered.

Both Wildcard SSL and SAN certificate will reduce the cost as well as management hassle. Read this article if you want to understand the difference between Wildcard SSL and SAN.

1
  • I think what OP was asking was that all domains would use the same data folder? I have that same problem right now too...
    – El Dude
    Nov 24, 2020 at 20:02
1

Followup on Gunjan Tripathi's answer, to have all domains use the same data directory you would set DocumentRoot to the same directory.

<VirtualHost *:443>
 ServerName site1.domain.com 
 DocumentRoot /var/www/html
 SSLEngine on
 SSLCertificateFile /path/to/site1_domain_com.crt
 SSLCertificateKeyFile /path/to/site1_domain_com.key
 SSLCertificateChainFile /path/to/CA.crt
</VirtualHost>

<VirtualHost *:443>
 ServerName site2.domain.com
 DocumentRoot /var/www/html
 SSLEngine on
 SSLCertificateFile /path/to/site2_domain_com.crt
 SSLCertificateKeyFile /path/to/site2_domain_com.key
 SSLCertificateChainFile /path/to/CA.crt
</VirtualHost>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .