LoneCoder
By:
LoneCoder

How do icorrectly setup my first virtual host correctly

February 10, 2017 811 views
LAMP Stack Ubuntu 16.04

Hello,
Firstly please excuse my 'Noobiness' but im new to VPS ...

I am having trouble displaying my first virtual host web content after following the DO tutorial here :
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04

I have completed the LAMP installation correctly step by step and all is working ok but when i come to displaying the test page in the virtual host i get the standard Chrome message :

This site can’t be reached
ERRNAMERESOLUTION_FAILED

I restarted my instance properly and waited 2 days for the propagation period (just in case) but i still get the error message. However when i go to the url of my digital Ocean Hostname it shows the example 'success' message in my virtual host file .html file.

Am i correct in thinking i need to change the name servers of the domain name for my virtual host site to the name servers of my Droplet/Hostname - currently they are pointing to Digital Oceans nameservers (primary, secondary and tertiary) - but they should point to those that i set up in my Digital Ocean control panel, right? which would be my Digital Ocean Hostname for NS records first, second and third, yes?

Also if this works then can i still show my main website on main hostname and a second site on my virtual host? or should i forget about virtual hosts and just have a separate server instance/droplet for each site i intend to build.

Thank you.

2 Answers

@LoneCoder

Apache allows you to host multiple sites and this can be done on a single Droplet, you just need to make sure you're VirtualHost blocks are properly setup -- the same for directories.

For VirtualHost setup, I'd take a closer look at this guide as it applies specifically to setting them up properly. You'd then mimic the contents of the guide and chance site-specific details (i.e. domain, paths, etc).

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04#step-four-%14-create-new-virtual-host-files

As for DNS, you'll need to setup your domain to use:

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

Then you need to setup an A and CNAME entry for your domain. The A entry points your domain to the IP of your droplet and the CNAME points www to your domain.

For example:

A          @       DROPLET_IP
CNAME      www     yourdomain.ext
The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 16.04 server.
  • Ive done this but when i type in the domain name on my virtual host i still get the error message:
    (Chrome) : ERRNAMERESOLUTION_FAILED

    BTW: after setting up the A record is it normal for the virtual hosts domain name to be shown prepended to the droplets IP address : vhostDomName.ext.dropletHostName.ext

@LoneCoder

To really diagnose the issue further I'd need to see your VirtualHost blocks for each of your domains and all the records that you have set for your DNS. Without those two things, it's hard to really guess at what could potentially be wrong as that's all I'd be doing, guessing :-).

Have another answer? Share your knowledge.