-2

I was trying to set up a virtual host in apache on my CentOS6 server that handles queries of a subdomain.

Let's say, I have the domain 'example.com'. Now, I want to create the sub domain test.example.com that serves another html page than the main domain.

I searched already for some instructions to do that, especially on apache.org and there were plenty of them, but no one worked.

The problem is: Whenever I visit test.example.com in my browser, I get the main page that is served by example.com althought DocumentRoot points to another directory.

I even tried this a minimal httpd configuration file containing nothing but the following code, but with no success.

Listen 80
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /www/main
</VirtualHost>

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

Have you an idea what the problem could be?

Green绿色
  • 101
  • 1

1 Answers1

0

Change order, make test.example.com VirtualHost in front (before) example.com VirtualHost, follow by restarting httpd service.

Listen 80
NameVirtualHost *:80
<VirtualHost _default_:80>
</VirtualHost>
<VirtualHost _default_:80>
 ServerName test.example.com
 DocumentRoot /www/test
</VirtualHost>
<VirtualHost _default_:80>
 ServerName example.com
 DocumentRoot /www/main
</VirtualHost>
alexus
  • 13,112
  • 32
  • 117
  • 174
  • Unfortunatelly, this did not work. When starting the httpd service I get the warning: "VirtualHost overlap on port 80, the first has precendence". The first one was the test domain, but I still get the index file of the main domain. – Green绿色 May 16 '15 at 17:28
  • you're missing something else; NameVirtualHost – alexus May 16 '15 at 18:00