Configuring SSL for Apache: Main Domain and Subdomain

Configuring SSL for Apache: Main Domain and Subdomain

Configuring SSL for Apache: Main Domain and Subdomain



1. Ensure Apache SSL Module is Enabled

sudo a2enmod ssl
sudo systemctl restart apache2
    

2. Configure SSL for Main Domain (luxyaragroup.io)

Create or Modify VirtualHost Configuration

  1. Navigate to Apache Sites Directory:
    cd /etc/apache2/sites-available
  2. Create or Edit Configuration File for Main Domain
    • Create a new configuration file or edit an existing one for luxyaragroup.io:
    • sudo nano luxyaragroup.io.conf
    • Example configuration for luxyaragroup.io:
    • <VirtualHost *:80>
          ServerName luxyaragroup.io
          DocumentRoot /var/www/html/luxyaragroup
      
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
      
      <VirtualHost *:443>
          ServerName luxyaragroup.io
          DocumentRoot /var/www/html/luxyaragroup
      
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      
          SSLEngine on
          SSLCertificateFile /etc/letsencrypt/live/luxyaragroup.io/fullchain.pem
          SSLCertificateKeyFile /etc/letsencrypt/live/luxyaragroup.io/privkey.pem
          SSLCertificateChainFile /etc/letsencrypt/live/luxyaragroup.io/chain.pem
      </VirtualHost>
                      
    • Replace /var/www/html/luxyaragroup with the actual document root path of your main domain.
  3. Enable SSL VirtualHost
    sudo a2ensite luxyaragroup.io.conf
  4. Restart Apache
    sudo systemctl restart apache2

3. Configure SSL for Subdomain (api.luxyaragroup.io)

Create or Modify VirtualHost Configuration

  1. Navigate to Apache Sites Directory:
    cd /etc/apache2/sites-available
  2. Create or Edit Configuration File for Subdomain
    • Create a new configuration file or edit an existing one for api.luxyaragroup.io:
    • sudo nano api.luxyaragroup.io.conf
    • Example configuration for api.luxyaragroup.io:
    • <VirtualHost *:80>
          ServerName api.luxyaragroup.io
          DocumentRoot /var/www/html/api
      
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
      
      <VirtualHost *:443>
          ServerName api.luxyaragroup.io
          DocumentRoot /var/www/html/api
      
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      
          SSLEngine on
          SSLCertificateFile /etc/letsencrypt/live/api.luxyaragroup.io/fullchain.pem
          SSLCertificateKeyFile /etc/letsencrypt/live/api.luxyaragroup.io/privkey.pem
          SSLCertificateChainFile /etc/letsencrypt/live/api.luxyaragroup.io/chain.pem
      </VirtualHost>
                      
    • Replace /var/www/html/api with the actual document root path of your subdomain.
  3. Enable SSL VirtualHost
    sudo a2ensite api.luxyaragroup.io.conf
  4. Restart Apache
    sudo systemctl restart apache2

4. Obtain SSL Certificates with Certbot

sudo certbot --apache -d luxyaragroup.io -d api.luxyaragroup.io

Follow the prompts to configure HTTPS for both domains.

5. Verify Configuration

After setting up SSL for both domains, verify that HTTPS is working correctly by accessing:

Ensure there are no SSL errors or warnings in the browser and that your sites are serving content securely over HTTPS.

Summary

By following these steps, you can configure SSL for both your main domain and subdomain on Apache successfully. Adjust paths, domain names, and additional SSL configuration directives as per your specific setup and requirements.

Post a Comment

1 Comments

  1. sudo apt update
    sudo apt install python3-certbot-apache -y
    sudo certbot --apache -d franchisepartners.online

    ReplyDelete