Apache virtual host doesn't load the index.html file

I wrote httpd.conf file, but it's not loading the index.html file. Whenever I type project URL in browser it says this site can't be reached.

<VirtualHost *:80> 
 ServerName www.linuxhelptesting.com
 DocumentRoot /var/www/html/sample1
</virtualhost>

What am I doing wrong here?


Solution 1:

As with your previous question, the problem you seem to be running into is likely DNS related. DNS maps a domain name (e.g. www.example.com) to an IP address (e.g. 1.2.3.4). When any computer wants to go to e.g. www.example.com, there is a process it follows to find the IP of the corresponding webserver. It seems likely that you have not correctly told anyone (even your own computer) how to find the correct IP where Apache is located when asking for e.g. www.linuxhelptesting.com. Note that Apache does not provide this kind of service (DNS). To solve this, you should do one of the following:

  1. Update your computer's hosts file to map the correct local IP to e.g. www.linuxhelptesting.com. Repeat this for any local computers you want to access the site.

  2. Set up a local DNS server (separate from Apache) with proper records to map domain names to IP addresses and ensure that it is the DNS server used by your local router. Then any device connected to your local network should be able to access e.g. www.linuxhelptesting.com without modifying the device's hosts file (assuming you have records mapping e.g. www.linuxhelptesting.com to the correct local IP of the Apache web server).

  3. Set up DNS records that point e.g. www.linuxhelptesting.com to your public IP. This can be done in several ways, but they will involve your domain registrar and either a third-party DNS provider or you setting up a DNS server yourself (somewhat similar to Option 2).