I just got a new cloud server and while setting it up, I can access the web root by pointing my browser to the IP address of my server, but the domain names are still propagating so when I go to them, they do not resolve.

When I do point my browser to the IP address of my server, it is actually resolving to the first VirtualHost that I set up which should not be the root folder. This VirtualHost should show up when I go to ipaddress/path, not just ipaddress.

Server setup:
Host: Rackspace Cloud Server
OS: CentOS 6

<VirtualHost *:80>
    ServerAdmin www.wphax.com@gmail.com
    ServerName www.wphax.com
    ServerAlias wphax.com *.wphax.com
    DocumentRoot /var/www/wphaxcom
    ErrorLog /var/www/wphaxcom/error.log
    CustomLog /var/www/wphaxcom/access.log combined
<VirtualHost *:80>
    ServerAdmin www.wphax.com@gmail.com
    ServerName www.dnadvanced.com
    ServerAlias dnadvanced.com *.dnadvanced.com
    DocumentRoot /var/www/dnadvancedcom
    ErrorLog /var/www/dnadvancedcom/error.log
    CustomLog /var/www/dnadvancedcom/access.log combined

Any ideas what could cause this, and how I could set it up so the root directory is not accessible by entering the IP address, but the domain names will resolve correctly to their specified folders? Thanks.

  • I don't see what the problem is. If you specify the IP address directly, and you have multiple servers mapped to that host, isn't it always going to resolve the first one you defined? It should function correctly once the DNS registries are updated across teh interwebz. – Breakthrough May 9 '12 at 2:59
  • Do you happen to have the NameVirtualHost *:80 directive present above both of your <VirtualHost> definitions? – Breakthrough May 9 '12 at 3:02
  • @Breakthrough Yes, NameVirtualHost *:80 is present above the VirtualHost definitions. -- Could it be because the domain names' nameservers are still propagating? – Jared May 9 '12 at 4:14
  • If I go to just the IP address of my server, I get the /var/www/wphaxcom directory. If I go to the IP/dnadvancedcom, it tries going to /var/www/wphaxcom/dnadvancedcom. – Jared May 9 '12 at 4:15

From the Name-based Virtual Host Support article in the Apache server documentation:

IP-based virtual hosts use the IP address of the connection to determine the correct virtual host to serve. [...]

Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames. [...]

By directly specifying an IP address, you are essentially selecting the first virtual host listed in your configuration file. Since you never specified an IP address in the configuration file, that host is listening on all IPs. How Apache determines what website to serve is dictated by the information received in the HTTP headers from the client's request.

Unless you can access both virtual hosts via independent IP addresses - or by different port numbers (i.e. set the second one to port 81) - you will have to wait for your domain name changes to propagate.

If you really need to test the server now, you can attempt to manually modify the HTTP headers after each request (using something like the Tamper Data addon for Firefox) so that Apache will serve the proper page to your browser.

  • I figured I would have to wait for the DNS to propagate. One other thing I forgot was to add the A records for my domain names. Started working right away after that. :) – Jared May 12 '12 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.