2

I have a site located at /var/www/html/ which works fine.

I'm now trying to setup "blog.example.com" by adding the following entry in httpd.conf

Setup1

<VirtualHost *:80>
DocumentRoot /var/www/html/blog
ServerName blog.example.com

</VirtualHost>

BUT now the main site stops working and nothing is accessible at: http://blog.example.com either

root@server [~]# apachectl configtest
Syntax OK

I tried the following but it didnt work either

Setup2

NameVirtualHost *:80

<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/html/blog

</VirtualHost>

(This is linked to https://serverfault.com/questions/209945/setting-up-blog-at-blog-example-com-httpd-conf-issue)

The site is running as user 'apache' on a RedHat/CentOS system.

I tried the following as well with no luck

Setup3

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.example.com
</VirtualHost>

<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/html/blog
</VirtualHost>

This was better because I was able to access the site, but the blog.example.com link was still not functional.


Setup5

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/html/blog
<Directory /var/www/html/blog/>
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>
</VirtualHost>

Setup6

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/html-blog
</VirtualHost>

In both cases, nslookup shows the following:

root@server [/etc/httpd/conf]# nslookup
> example.com
Server:         67.99.9.90
Address:        67.99.9.90#53

Non-authoritative answer:
Name:   example.com
Address: 174.999.99.99
> blog.example.com
Server:         67.99.9.90
Address:        67.99.9.90#53

** server can't find blog.example.com: NXDOMAIN

3 Answers 3

1

You should check the Apache Documentation on Name-Based Virtual Hosts Support so you might read the following:

Main host goes away

If you are adding virtual hosts to an existing web server, you must also create a block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.

Edit:

Hence the main Site is online again we should assume on Apaches side everything works. It seems we are not dealing with an issue regarding HTTP/1.1 VHosts (Name-Based Virtual Hosts) since the same features are being used as well for the main site as for the blog.

Now let's see why blog.example.com isn't working. You should check the DNS Record of blog.example.com since it should point to the same address as example.com

$ nslookup
> example.com
[...]
> blog.example.com
[...]
> quit

Edit 2

Regarding what that nslookup did not return a result for the subdomain the problem is explained. The request for blog.example.com never reaches your apache webserver because the DNS server doesn't know what to do with blog.example.com.

So regarding what we see and know, your apache configuration seems to be correct. The main page is online again after we added its VirtualHost. So since I trust you did it right for blog. too.

What follows no depends on the DNS Provider of the domain. The easiest thing would be to put a wildcard subdomain on example.com to redirect to your webserver. This will redirect any request for ANYTHING.example.com to your webserver which handles the rest with the VirtualHosts you configured in apache.

Remember DNS Server take some time before their caches are updated. So these changes might take some time.

3
  • Hi @pacey - have a look at Setup3 above - I think it does exactly what the link you mentioned says to do, but that didnt work for me...
    – siliconpi
    Dec 8, 2010 at 10:28
  • @matt_tm: Your Setup3 deals correctly with the issue of the disappearing mainhost. Since your mainhost is up again the blog. issue might be something other.
    – pacey
    Dec 8, 2010 at 10:47
  • do i have to wait for a while or is this instantaneous?
    – siliconpi
    Dec 9, 2010 at 10:28
1

First question is how are you defining "non-functional"? Are you getting an error from the server? (What's the error?)

Are you getting the main page rather than the blog page? (Something might be broken with the Named VirtualHosts configuration)

Are you not connecting at all? (DNS issue? Is anything showing up in the Apache logs?)

A few thoughts... A) can you try to explicitly add a Directory directive for the blog the subtree and see if that makes a difference.

<Directory /var/www/html/blog/>
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

A) What happens if you move the blog tree into it's on directory structure, say /var/www/html-blog and update your httpd.conf to reflect it...

<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/html-blog
<Directory /var/www/html-blog/>
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>
</VirtualHost>
2
  • see setup5 - i tried that and it didnt work either
    – siliconpi
    Dec 9, 2010 at 10:29
  • Well, there's your issue... "** server can't find blog.example.com: NXDOMAIN" You need to update the DNS to add the IP for blog.example.com
    – Chris
    Dec 9, 2010 at 14:54
-2

In the main http configuration, do you have the line:

NameVirtualHost *

uncommented? Else virtual hosts won't work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .