Virtual Hosts displays the same pages

Support for webhosts that use CentOS
Post Reply
madal30
Posts: 37
Joined: 2008/12/08 14:06:02

Virtual Hosts displays the same pages

Post by madal30 » 2010/08/11 15:43:54

Hi all,

I dont know what is going wrong on my vhost setting. I have a one IP address with hostname and a cname. So I wanted run two website on this.

test1.abc.com
test2.abc.com

test2.abc.com IN CNAME test1.abc.com
test1.abc.com IN A 192.168.1.1

Then I edited in my httpd.conf as this


ServerName test2.abc.com
DocumentRoot /var/www/html/test


After restarting the apache. in browser i can see the same page as test1.abc.com and test2.abc.com. I have different content. Any help would be appericiated.

M

logan
Posts: 64
Joined: 2008/08/01 16:40:34

Virtual Hosts displays the same pages

Post by logan » 2010/08/11 20:23:22

Is test2.abc.com the only configured VirtualHost? If so, that's normal behavior. The first VirtualHost Apache finds will be used for any requests to unknown/unconfigured hostnames and domains. I always configure the first vhost on servers at work to redirect people to the main company website on dedicated boxes or my work's site for shared servers.

jaylakes
Posts: 5
Joined: 2010/05/01 13:26:41

Re: Virtual Hosts displays the same pages

Post by jaylakes » 2010/08/11 21:30:28

The vhosts.conf file would need to read something like this:

NameVirtualHost *:80


ServerName test1.abc.com
DocumentRoot /var/www/html/test1



ServerName test2.abc.com
DocumentRoot /var/www/html/test2




------------------------------------------------------

See the output of "httpd -s" for more information.

madal30
Posts: 37
Joined: 2008/12/08 14:06:02

Re: Virtual Hosts displays the same pages

Post by madal30 » 2010/08/12 08:56:15

here is my virtual host section looks like.


ServerName test2.abc.com
DocumentRoot /tmp/test/


I leave the default setting for test1.abc.com and just added the above section for virutal host. I still get the same pages.

M

logan
Posts: 64
Joined: 2008/08/01 16:40:34

Re: Virtual Hosts displays the same pages

Post by logan » 2010/08/12 19:13:23

The main server is different from virtual hosts. When using vhosts, you need to configure one for every site you want to host (like jaylakes's example). Take any custom configuration from the main server (redirects, allow/deny, overrides, documentroot, logging, etc) and throw it into a vhost for test1.abc.com, then [i]/etc/init.d/httpd graceful[/i] and try again.

madal30
Posts: 37
Joined: 2008/12/08 14:06:02

Re: Virtual Hosts displays the same pages

Post by madal30 » 2010/08/13 18:06:08

Hi all,

Do you mean leave the global setting as it is then all the custom setting dum into test1 virtual host section ? Basically two virtual server test1 (main server) and test2 right ?

would like this
NameVirtualHost *:80


ServerName test1.abc.com
ServerAdmin madal@abc.com
DocumentRoot /tmp/test1




ServerName test2.abc.com
DocumentRoot /tmp//test2


Do you have example something like what i am trying to do ?

Thanks
M

rocafella
Posts: 1
Joined: 2010/08/16 21:56:52

Re: Virtual Hosts displays the same pages

Post by rocafella » 2010/08/17 06:59:29

Hi

In my case virtual host dont work because of missing index.html file

Below is working solution

nano /etc/httpd/conf/httpd.conf

add the following section

NameVirtualHost *:80

ServerName centos
DocumentRoot /var/www/html/

Include /etc/httpd/vhosts.d/*.conf

Create folders

mkdir /etc/httpd/vhosts.d/
mkdir –p /var/www/vhosts/rocafella/

Create vhost config

nano /etc/httpd/vhosts.d/rocafella.conf


ServerName rocafella
DocumentRoot /var/www/vhosts/rocafella/



Create test index.html

nano /var/www/vhosts/rocafella/index.html

test


service httpd restart

madal30
Posts: 37
Joined: 2008/12/08 14:06:02

Re: Virtual Hosts displays the same pages

Post by madal30 » 2010/08/17 13:38:59

Hello all,

Thanks for your all replies. Finally my vhost in fact works now. here is what i had to do.

NameVirtualHost *:80

ServerName test1.abc.com
DocumentRoot "/var/www/html/"



ServerName test2.abc.com
DocumentRoot "/var/www/vhosts/seti/"



i commented the DocumentRoot that was in default. but question is how many virtual server can be setup in port 80 ?

Madal

logan
Posts: 64
Joined: 2008/08/01 16:40:34

Re: Virtual Hosts displays the same pages

Post by logan » 2010/08/17 18:13:46

I'm not aware of any limit. I've got 206 's on a development server at work. You'll probably hit the maximum number of open file descriptors before anything else (lots of Custom/Transfer/ErrorLog directives).

Post Reply

Return to “CentOS 5 - Webhosting Support”