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
Best Answer
You should check the Apache Documentation on Name-Based Virtual Hosts Support so you might read the following:
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
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 withblog.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.