Setting up multiple domains and subdomains on one droplet?

August 13, 2015 4.4k views
Configuration Management Apache LAMP Stack Deployment

will add info via mobile

  • Wondering if anyone can point me in the right direction on this? I did a lot of searching last night on Google but couldn't seem to find someone doing this same scenario. I've included a write up below of what I'm trying to do.

    We have one droplet (which is like server instance with static IP) on account and need to set it up so that we can have multiple subdomains that each point to different subdomain within /var/www

    We will also add other domains to this same server, so it will have, for example: --> /var/www/somedomain --> /var/www/test1somedomain --> /var/www/test2somedomain --> /var/www/anotherdomain --> /var/www/test1anotherdomain

  • sorry, had to post as comment, this forum is very broken on a mobile device.

2 Answers

Hello, it isnt that hard to get something like this and easily to find on google. I think you searched on the wrong keywords ;) Just add the domains you would like to use to your digital ocean domain manager. To get this working you need to setup your nameservers correctly. Login to the domain manager of your registrar, edit the nameservers to the nameservers of DO and it should work after some time.

Once you got the domains in the DO domainmanager, you need to create A records for the subdomains etc. to your static IP. So people will get redirected to your server.

After this you are almost done. Now you got the domain working, redirected to your server , you got to let your server handle the domain/subdomain to the proper directory. This depends on the kind of webserver you are using. With apache you need to use a different kind of virtual host than when you are using nginx for example. Just search for apache ,or whatever webserver your using, virtual host.

Hope this helps you, if I missed something im sorry im on my ipad currently.

Thanks, I am using apache and was trying different configurations with the virtual host, I can search more on it though

  • You don't need to use a advanced apache virtualhost when not needed. What you need to do is easy;

    • Create a new virtual host conf in sites-available, name it like or (It doesnt really matter, but easy to manage)
    • In your virtualhost use something like this:
    <VirtualHost *:80>
        DocumentRoot /var/www/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    • Change the needed options in your virtualhost. So change the servername, so apache handles the correct domain; the documentroot; alias etc.
    • Enable your new viritualhost with:
    (sudo) a2ensite
    • Restart your apache:
    (sudo) service apache2 restart
Have another answer? Share your knowledge.