I created a new droplet lamp-ubuntu for myDomain.com, all works well with DocumentRoot as /var/www/html with a Let’s Encyrpt SSL certificate. I also have 000-default.conf and 000-default-le-ssl.conf config files in /etc/apache2/sites-available.
but I would like to make a few changes …
I want to add myDomain.net to the same droplet and I’ve organised my html files as follows
/var/www/html (keeping this the same while I make sure my changes work ok)
/var/www/html/myDomain.com
/var/www/html/myDomain.net
both with Let’s Encrypt SSL certificates.
can anyone advise what steps to take?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya @fingers,
Yes, sure. You just need to create another conf file in /etc/apache2/sites-available.
First create the /etc/apache2/sites-available/mydomain.net.conf file. Inside you can put something like the following:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myDomain.net
ServerAlias www.myDomain.net
DocumentRoot /var/www/html/myDomain.net
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
That should be enough for now. Save the file. After that run
sudo a2ensite mydomain.net.conf
Now your Website if having the proper DNS record will start loading from your Droplet.
As for SSL, you can run the certbot command it will guide you through the proccess of installing an SSL certificate for your Domain and creating the proper virtual host for your 443 port.
Hi there,
Would the second domain be loading a totally separate website? Or would it just need to show the content of your already existing website?
To add a second domain and a second website to your existing Droplet with Apache and Let’s Encrypt SSL certificates, follow these steps:
Prepare Your Directory Structure: Ensure your directories are structured as:
/var/www/html
/var/www/html/myDomain.com
/var/www/html/myDomain.net
Create New Virtual Host Configuration Files:
You’ll need to create new configuration files for both myDomain.com and myDomain.net.
Create the Virtual Host for myDomain.com:
sudo nano /etc/apache2/sites-available/myDomain.com.conf
Add the following content:
<VirtualHost *:80>
ServerName myDomain.com
ServerAlias www.myDomain.com
DocumentRoot /var/www/html/myDomain.com
<Directory /var/www/html/myDomain.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/myDomain.com-error.log
CustomLog ${APACHE_LOG_DIR}/myDomain.com-access.log combined
</VirtualHost>
Create the Virtual Host for myDomain.net:
sudo nano /etc/apache2/sites-available/myDomain.net.conf
Add the following content:
<VirtualHost *:80>
ServerName myDomain.net
ServerAlias www.myDomain.net
DocumentRoot /var/www/html/myDomain.net
<Directory /var/www/html/myDomain.net>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/myDomain.net-error.log
CustomLog ${APACHE_LOG_DIR}/myDomain.net-access.log combined
</VirtualHost>
Enable the New Virtual Hosts:
sudo a2ensite myDomain.com.conf
sudo a2ensite myDomain.net.conf
sudo systemctl reload apache2
Obtain SSL Certificates Using Let’s Encrypt: Use Certbot to obtain SSL certificates for both domains. If you don’t have Certbot installed, install it first:
sudo apt update
sudo apt install certbot python3-certbot-apache
Obtain and Install the Certificate for myDomain.com:
sudo certbot --apache -d myDomain.com -d www.myDomain.com
Obtain and Install the Certificate for myDomain.net:
sudo certbot --apache -d myDomain.net -d www.myDomain.net
Certbot will automatically configure your Apache virtual host files to use SSL. It will create corresponding SSL configuration files (e.g., myDomain.com-le-ssl.conf and myDomain.net-le-ssl.conf) in /etc/apache2/sites-available.
Verify the SSL Configuration: Certbot should have reloaded Apache automatically, but it’s good to verify:
sudo apachectl configtest
sudo systemctl reload apache2
Let me know how it goes!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.