Vhosts

Support for webhosts that use CentOS
Post Reply
costas
Posts: 1
Joined: 2010/07/15 07:05:32

Vhosts

Post by costas » 2010/07/15 07:34:56

Hi,

I am a newbee to Apache and I am trying to configure vhost so that my server will be able to handle traffic for two web pages. However, I only have one registered domain (for the moment) and my server has a single IP; thus, I would like the one web page to be accessible when using the domain name and the other when using the IP address.

Is that possible? I tried different settings but none of them worked.

Currently, I have only one active vhost. However, apache serves every request coming for the domain, allowing access to web pages that are not under the /var/www/html/MYDOMAIN. For example if a request www.MYDOMAIN.org/~user1 come, the web page of user1 is return despite the fact that is located under /home/user1/public_html.

Bellow, is my current configuration of the vhost.

#
# DocumentRoot /var/www/html/joomla
#


DocumentRoot /var/www/html/MYDOMAIN
ServerName www.MYDOMAIN.org


Thanks for the help,
costas

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

Re: Vhosts

Post by logan » 2010/08/03 23:13:33

mod_userdir may persist across the main host and vhosts. So if you've got it enabled in /etc/httpd/conf/httpd.conf, that could explain why ~user1 is working. Or maybe that part is just confusing me... I think what you'd need to do to access a unique DocumentRoot for a specific IP address and still be hosting other sites on the box (that also use the same IP, is this the case?) is to configure multiple virtual hosts with the IP address:

[code]
NameVirtualHost *:80
NameVirtualHost ipaddr:80

<VirtualHost *:80>
ServerName catchall
DocumentRoot /var/www/html
</VirtualHost>

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

<VirtualHost ipaddr:80>
ServerName catchall
DocumentRoot /var/www/html/joomla
</VirtualHost>

<VirtualHost ipaddr:80>
ServerName www.MYDOMAIN.org
DocumentRoot /var/www/mydomain
</VirtualHost>
[/code]

That's an example where you'd have multiple IP addresses on the box, like an internal and an external interface. *:80 handling the external, ipaddr:80 handling the internal and mydomain.org is on the internal.

Maybe you could just simplify this and stick with / use [i][/i] for everything and setup a vhost that maches a made up entry you'll set in /etc/hosts or c:\windows\system32\drivers\etc\hosts, bypass the IP part and stick with a name-based hosting:
[code]
NameVirtualHost *:80

<VirtualHost *:80>
ServerName catchall
DocumentRoot /var/www/html
Redirect / http://www.MYDOMAIN.org/
</VirtualHost>

<VirtualHost *:80>
ServerName www.MYDOMAIN.org
DocumentRoot /var/www/mydomain
</VirtualHost>

<VirtualHost *:80>
ServerName domainyouplantoregister.org
DocumentRoot /var/www/html/joomla
</VirtualHost>
[/code]

Then [i]ipaddr domainyouplantoregister.org[/i] in the hosts file.

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

Re: Vhosts

Post by madal30 » 2010/08/11 15:20:02

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.rhi.hi.is. 86400 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

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Vhosts

Post by pschaff » 2010/08/11 15:23:32

[b]madal30[/b] - Please review [url=http://www.centos.org/modules/newbb/viewtopic.php?topic_id=14274&forum=47]Readme First, Section 7[/url] and do not hijack threads. Start a new Topic for your issue.

Post Reply

Return to “CentOS 5 - Webhosting Support”