SSL

How To Set Up Multiple SSL Certificates on One IP with Apache on Ubuntu 24.04

Welcome back to the Greenhost.cloud blog! As web security becomes increasingly important, many site owners are investing in SSL certificates to secure their web traffic. But what if you have multiple domains and want to serve all of them over HTTPS, yet you’re limited to a single IP address? In this guide, we’ll walk you through the steps to set up multiple SSL certificates on one IP using Apache on Ubuntu 24.04.

What You’ll Need

Before you begin, ensure you have the following:

  • A server running Ubuntu 24.04 with Apache installed.
  • Root access or sudo privileges on your server.
  • Domain names pointing to your server’s IP address.
  • SSL certificates for each domain. You can obtain these from a Certificate Authority (CA), or use Let’s Encrypt for free SSL certificates.

Step 1: Install Required Packages

First, make sure your server’s package list is updated and install the necessary packages. Open your terminal and run the following commands:

sudo apt update
sudo apt install apache2 certbot python3-certbot-apache

The certbot package allows you to obtain and manage SSL certificates easily.

Step 2: Obtain SSL Certificates

If you’re using Let’s Encrypt, you can obtain SSL certificates for your domains automatically with Certbot. Replace example.com and www.example.com with your actual domain names:

sudo certbot --apache -d example.com -d www.example.com

Follow the prompts to complete the certificate installation. Repeat the command for each domain you want an SSL certificate for, adjusting the domain names accordingly.

Step 3: Configure Apache for Multiple SSL Certificates

Once you have obtained all your SSL certificates, the next step is to configure Apache to serve them correctly. Open your Apache configuration file or create new virtual host configuration files for each domain.

  1. Navigate to the /etc/apache2/sites-available/ directory:
   cd /etc/apache2/sites-available/
  1. Create a configuration file for each domain. For example, create example.com.conf:
   sudo nano example.com.conf

And add the following configuration:

   <VirtualHost *:80>
       ServerName example.com
       ServerAlias www.example.com
       Redirect permanent / https://example.com/
   </VirtualHost>

   <VirtualHost *:443>
       ServerName example.com
       ServerAlias www.example.com

       DocumentRoot /var/www/example.com

       SSLEngine on
       SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
       SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

       <Directory /var/www/example.com>
           Options Indexes FollowSymLinks
           AllowOverride All
           Require all granted
       </Directory>
   </VirtualHost>
  1. Repeat the above step for other domains, changing the ServerName and ServerAlias, as well as the DocumentRoot and paths to SSL certificate files accordingly.

Step 4: Enable the New Virtual Host Configurations

After creating the configuration files, you need to enable them and restart Apache to apply the changes:

sudo a2ensite example.com.conf
sudo a2ensite another-example.com.conf
sudo systemctl restart apache2

Replace another-example.com.conf with the actual configuration files for any additional domains.

Step 5: Test Your SSL Configuration

Open a web browser and navigate to your domains using https://. Ensure that the SSL certificates are correctly applied and that the sites are accessible over HTTPS. You can also use online SSL tools like SSL Labs to test your configuration for security and issues.

Conclusion

By following the steps above, you can successfully set up multiple SSL certificates for different domains on the same IP address using Apache on Ubuntu 24.04. As an important note, remember to renew your Let’s Encrypt certificates every 90 days or set up a cron job to automate this process.

At Greenhost.cloud, we’re committed to providing you with the best hosting solutions for your needs. If you have any questions or need assistance with your setup, feel free to reach out!

Happy hosting! 🌍🔒