Virtual hosts

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Virtual hosts

Postby zzeljko » 21. March 2008 19:11

I have site1 and site2 on the same IP address.

site1 is configured as Apache main site and site2 is configured as virtual host.

When I go to site3 (which shares the IP with site1 and site2) I get site2 displayed.

How do I set up Apache to serve site1 for all the sites that are not defined in any of the virtual hosts?
zzeljko
 
Posts: 9
Joined: 05. January 2008 18:52

Postby Wiedmann » 21. March 2008 19:12

Site 1 must be the first virtualhost (in the namevirtual hosts group).
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby zzeljko » 21. March 2008 19:17

Wiedmann wrote:Site 1 must be the first virtualhost (in the namevirtual hosts group).


I tried that as well, but with no success.

Here are the relevant parts from Apache configuration:

Listen 127.0.0.1:80
DocumentRoot "C:/site1"

NameVirtualHost 127.0.0.1:80
<VirtualHost _default_:80>
</VirtualHost>

<VirtualHost 127.0.0.1:80>
DocumentRoot "C:/ip"
</VirtualHost>

<VirtualHost 127.0.0.1:80>
ServerName "site2"
DocumentRoot "C:/site2"
</VirtualHost>

When I go to site1 I get C:/site1 content. That's OK.
When I go to site2 I get C:/site2 content. That's OK.
When I enter 127.0.0.1 in browser, I get C:/ip content. That's OK.
BUt when I go to site3 (not defined anywhere in Apache) I get C:/ip, but what I'd want is c:/site1 served.
zzeljko
 
Posts: 9
Joined: 05. January 2008 18:52

Postby zzeljko » 21. March 2008 19:43

If I put the following configuration:

Listen 127.0.0.1:80
DocumentRoot "C:/site1"

NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:/site1"
</VirtualHost>

<VirtualHost 127.0.0.1:80>
ServerName "site2"
DocumentRoot "C:/site2"
</VirtualHost>

...then site1, site2 and site3 works as I want them to work, but I can no longer access c:/ip via 127.0.0.1
zzeljko
 
Posts: 9
Joined: 05. January 2008 18:52

Postby Wiedmann » 21. March 2008 20:37

IMHO you can make something like:
httpd-vhosts.conf:
Code: Select all
<VirtualHost 127.0.0.1:80>
    ServerName localhost:80
    DocumentRoot "C:/ip"
</VirtualHost>

NameVirtualHost 192.168.0.1:80
<VirtualHost 192.168.0.1:80>
    ServerName site1:80
    DocumentRoot "C:/site1"
</VirtualHost>
<VirtualHost 192.168.0.1:80>
    ServerName site2:80
    DocumentRoot "C:/site2"
</VirtualHost>


HOSTS: (e.g.)
Code: Select all
127.0.0.1 localhost
192.168.0.1 site1
192.168.0.1 site2
192.168.0.1 site3


("192.168.0.1" is the lan ip from yoru pc)
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby zzeljko » 21. March 2008 22:53

Yeah, that works fine. But what I would like is to have it all under a single IP address. I wanted a site1 and site2 to be served when they are requested (virtual hosts), at the same time to be able to access the third site via IP address, and all other requests (site3, .....) which are not explicitly defined to be served from "C:/site0".

I've spent this afternoon browsing through Apache documentation and it seems that can not be done. It's either IP based virtual hosts or name based virtual hosts, but not combination of those two.

I thought I'd solve the problem by putting "ServerName 127.0.0.1" in vHost and hoping Apache will serve that vHost when IP is entered in browser, but that isn't the case.

I suppose I'll have to rearange this whole idea (most likely not using IP address or using RewriteRule to distinguish when the IP site is entered).
Anyway, thank you for your assistance.
zzeljko
 
Posts: 9
Joined: 05. January 2008 18:52

Postby Wiedmann » 22. March 2008 01:20

Yeah, that works fine. But what I would like is to have it all under a single IP address.

Maybe you should better describe your problem ;-) Or I don't understand it correct...

In your last post we have had 3 DocumentRoots:
DocumentRoot "C:/ip"
DocumentRoot "C:/site1"
DocumentRoot "C:/site2"

and 4 dns names (for browser access):
localhost (DocumentRoot "C:/ip")
site1 (DocumentRoot "C:/site1")
site2 (DocumentRoot "C:/site2")
site3 (DocumentRoot "C:/site1")

2 ip address (for browser access):
127.0.0.1 (DocumentRoot "C:/ip")
192.168.0.1 (DocumentRoot "C:/site1")

(That's what my code is doing)


And now we have an additional 4rd DocumentRoot?
DocumentRoot "C:/site0" accessed via ip? (which ip: 192.168.0.1?)
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby zzeljko » 22. March 2008 13:10

Hi,

I see some discrepancies in previous posts.

I'll explain the problem again, removing all of the unnecessary information.

You have the hosts file:
Code: Select all
192.168.0.1 site1
192.168.0.1 site2
192.168.0.1 site3

192.168.0.1 being the IP address assigned to network card.

Using that address and that address alone (no 127.0.0.1), I want all of the following to be true:
1) When user enters site1 in browser, C:\site1 is served
2) When user enters 192.168.0.1 in browser, C:\ip is served
3) When user enters anything else (site2, site3) that resolves to the 192.168.0.1, default site is displayed (C:\default)

I've accomplished parts 1 and 2, but I have difficulties with part 3.

The solution that will solve all of my problems is a directive which checks for IP address rather then HTTP Host header (ServerName) but as I browsed through the documentation, I don't believe there is any.

I can post parts of Apache configuration if you believe I might have misconfigured it.
zzeljko
 
Posts: 9
Joined: 05. January 2008 18:52


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 32 guests