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
- Navigate to Apache Sites Directory:
cd /etc/apache2/sites-available
- 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
- Create a new configuration file or edit an existing one for
- Example configuration for
luxyaragroup.io
: - Replace
/var/www/html/luxyaragroup
with the actual document root path of your main domain. - Enable SSL VirtualHost
sudo a2ensite luxyaragroup.io.conf
- Restart Apache
sudo systemctl restart apache2
<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>
3. Configure SSL for Subdomain (api.luxyaragroup.io)
Create or Modify VirtualHost Configuration
- Navigate to Apache Sites Directory:
cd /etc/apache2/sites-available
- 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
- Create a new configuration file or edit an existing one for
- Example configuration for
api.luxyaragroup.io
: - Replace
/var/www/html/api
with the actual document root path of your subdomain. - Enable SSL VirtualHost
sudo a2ensite api.luxyaragroup.io.conf
- Restart Apache
sudo systemctl restart apache2
<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>
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.
1 Comments
sudo apt update
ReplyDeletesudo apt install python3-certbot-apache -y
sudo certbot --apache -d franchisepartners.online