How to host a subdoman and main domain in a same droplet?

I have a droplet in Ubuntu 14.04,what I want to do is create a subdomain and host it in the same droplet.

My main domain : Subdomain created :

**What I tried so far: **

  1. Created a “A” record for in Networking section

  2. Created a CNAME record for

  3. Set up the virtual host for following this How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

**Below is the step I tried to set up the virtual host **

  1. The droplet is installed Apache2 before,so I didnt install again

  2. Create the directory for my by using this command sudo mkdir -p /var/www/

  3. Create a demo page by using this command nano /var/www/ and add a simple html code inside it .

  4. I copy the 000-default.conf to my new created conf like this sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/

  5. I change the to the following:

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
  1. Lastly I use this command to enable the virtual host for sudo a2ensite and restart the apache by sudo service apache2 restart

After all this step, I test my subdomain,but it doesnt work.It said refused to connect

so what I missing here?? Can somebody help??


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I don’t understand - you cannot get IP with dig but with host you can ?

Please run these commands and paste outputs: dig NS +short dig +short dig +short

It seems to be DNS problem. Please try to override default DNS on your PC, not server by adding 2 lines in “hosts” config file. On Linux/Mac it’s in /etc/hosts. On Windows it’s in %WINDIR%\system32\drivers\etc\hosts. Any changes need to be made with highest privileges by root or Administrator.

Add 2 new lines:


And try site in browser.

Is DNS pointing to your Droplet IP dig and dig ?

Is Apache2 listening on 80 port netstat -tlnpu | grep -i 'apache' ?

Do you have any firewall iptables -nvL with Drop policy and not allowed ports 80 ? Maybe ufw is installed and filtering ports.

Is your config correctly loaded by Apache2 apache2ctl -S ?