By samunyi90
Hello members, can one host several projects for instance 3, on the same droplet using subdomains? I’m using Apache as web server. I would wish to serve three sites as follows:
sub_1.example.com sub_2.example.com sub_3.example.com
Your assistance will be highly appreciated.
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!
Accepted Answer
Hey @samunyi90,
Yes, you can definitely host multiple sites on the same DigitalOcean Droplet using subdomains. Apache allows this through a feature called VirtualHosts. A VirtualHost can be configured for each subdomain. Below are the general steps you would need to take:
mkdir -p /var/www/sub_1.example.com/public_html
mkdir -p /var/www/sub_2.example.com/public_html
mkdir -p /var/www/sub_3.example.com/public_html
Make sure you set appropriate permissions for these directories.
sudo nano /etc/apache2/sites-available/sub_1.example.com.conf
Inside this file, you would put:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName sub_1.example.com
DocumentRoot /var/www/sub_1.example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file.
Do the same for sub_2 and sub_3, just replace sub_1
with sub_2
and sub_3
respectively in the above steps.
sudo a2ensite sub_1.example.com.conf
sudo a2ensite sub_2.example.com.conf
sudo a2ensite sub_3.example.com.conf
sudo systemctl restart apache2
That’s it! You now have three sites being served from the same Droplet, each from their own subdomain. If you have SSL certificates, you can configure each VirtualHost to also listen on port 443 and point to the respective certificates. This setup can be repeated for any number of sites you need to host.
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.