Forum Moderators: phranque

Message Too Old, No Replies

VirtualHost configuration problem

not working and I can't see why

         

shortbus

2:33 pm on Sep 10, 2004 (gmt 0)

10+ Year Member



Hey guru guys... I have been trolling here for a while... Now I need help cause I must be stupid.

Two FQDN's;
http://www.example2.com
and
http://www.example.com

I want to VirtualHost from the one server.
Here is my httpd.conf:


ServerName 192.***.***.***:80

UseCanonicalName On

NameVirtualHost 192.***.***.***:80

<VirtualHost www.example.com:80>
ServerName www.example.com
ServerAlias example.com *.example.com
DocumentRoot /home/jail/home/example/html
ServerAdmin admin@example.com
</VirtualHost>

<VirtualHost www.example2.com:80>
ServerName www.example2.com
ServerAlias example2.com *.example2.com
DocumentRoot /var/www/html
ServerAdmin admin@example2.com
</VirtualHost>

The output of "apachectl -t -D DUMP_VHOSTS" is


VirtualHost configuration:
192.***.***.***:80 is a NameVirtualHost
default server www.example.com (/etc/httpd/conf/httpd.conf:1095)
port 80 namevhost www.example.com (/etc/httpd/conf/httpd.conf:1095)
port 80 namevhost www.example2.com (/etc/httpd/conf/httpd.conf:1103)
wildcard NameVirtualHosts and _default_ servers:
_default_:443 new.host.name (/etc/httpd/conf.d/ssl.conf:90)
Syntax OK

The output of the DNS lookup seems right:
<snip>

When you got to http://www.example.com you go right to what http://www.example2.com is.

If you goto http://www.example2.com/~example you get what http://www.example.com *should* be

-- but the URL goes to: http://192.***.***.***/~example/forum/index.php

Can someone help me find what is missing? Or what I am doing wrong?

TIA

[edited by: jdMorgan at 6:30 pm (utc) on Sep. 10, 2004]
[edit reason] Removed specifics. Please see TOS. [/edit]

gergoe

7:04 pm on Sep 10, 2004 (gmt 0)

10+ Year Member



I would not use hostnames in the VirtualHost containers as this causes the Apache to look up the hostname on startup, which sometimes not working (inproperly configured dns server, parazite zones, etc). Just simply use *:80 or the ip adddress if you want to mix ip and name nased virtualhosting.
Additonaly I'm not sure that the Apache supports wildcards in the ServerAlias directive, at least it is not documented.
Last, it is pretty useless to define the ServerName in the way you did, I'd rather configure it to localhost or something like that if you don't have a "main" website. Actually this directive is used only if Apache is used as a standalone server (no vhosts), or if Apache is listening on more ip addresses than it is covered by the different virtualhosts.

So I'd change it as follows:


Port 80
[i]# OR[/i]
Listen 192.168.0.1:80
[small]# Use Port 80 if you don't use SSL, otherwise you need several Listen directives[/small]

ServerName www.mydomain.com

UseCanonicalName On

NameVirtualHost 192.168.0.1:80

<VirtualHost 192.168.0.1:80>
ServerName www.example.com
ServerAlias example.com sub.example.com
DocumentRoot /home/jail/home/example/html
ServerAdmin admin@example.com
</VirtualHost>

<VirtualHost 192.168.0.1:80>
ServerName www.example2.com
ServerAlias example2.com sub.example2.com
DocumentRoot /var/www/html
ServerAdmin admin@example2.com
</VirtualHost>

shortbus

6:30 am on Sep 11, 2004 (gmt 0)

10+ Year Member



Okay I made changes and I have the following:
----------------------------------------
Listen 80

ServerName www.example.com

UseCanonicalName On

NameVirtualHost 192.168.0.1:80

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

<VirtualHost 192.168.0.1:80>
ServerName www.example2.com
DocumentRoot /home/jail/home/example/html
</VirtualHost>

----------------------------------------
This is what I have for bare simplicity.

I have <VitualHost *:80> for the catch all default. Everything in -D DUMP_VHOSTS looks fine. Status OK.

www.example.com - works
www.example2.com - works exactly like www.example.com

www.example.com/~user1 == www.example2.com/~user1

It seems as if the DocumentRoot is not being read.
The correct ServerName is in the address bar, but it is not "taking on" the document root.

The said changes did have a positive impact... but I am not "there" yet.

Any suggestions?

gergoe

11:04 am on Sep 11, 2004 (gmt 0)

10+ Year Member



Check that the ip address specified in the NameVirtualHost matches (all of) the ip address of each domain, or use a wildcard instead, like this:

NameVirtualHost *:80

shortbus

12:25 pm on Sep 11, 2004 (gmt 0)

10+ Year Member



I tried this:

NameVirtualHost *:80

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

<VirtualHost 192.168.0.1:80>
ServerName www.example2.com
DocumentRoot /home/jail/home/example/html
</VirtualHost>

case: when using "NameVirtualHost *:80" -t -D DUMP_VHOSTS gives:
[warn] VirtualHost 192.168.0.1:80 overlaps with 192.168.0.1, perhaps you need a VirtualHost directive
/usr/sbin.apachectl: line 83: 5858 Segmentation fault $HTTPD $ARGV

and

NameVirtualHost 192.168.0.1:80

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

<VirtualHost 192.168.0.1:80>
ServerName www.example2.com
DocumentRoot /home/jail/home/example/html
</VirtualHost>

case: when using "NameVirtualHost 192.168.0.1:80" -t -D DUMP_VHOSTS gives:

192.168.1.1:80 is a NameVirtualHost
default server is www.example.com
port 80 namevhost www.example.com
port 80 namevhost www.example2.com
wildcard NameVirtualhost and _default_ servers:
_default_:443 new.host.name

So, only going with the second config from here....
when NameVirtualHost 192.168.0.1 is used (everything is exactly like the second config.)


NameVirtualHost 192.168.0.1:80

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

<VirtualHost 192.168.0.1:80>
ServerName www.example2.com
DocumentRoot /home/jail/home/example/html
</VirtualHost>

(again just to be clear the above config is what I am using.)

It occured to me that the header MUST be getting stripped. Because www.example.com == www.example2.com

When I make www.example2.com the default by wildcard is still get www.example2.com == www.example.com

www.example2.com goes to the DocumentRoot of /home/jail/home/example2/
but so does www.example.com -- which is the same problem I had before; only reversed Servername.

The oddity is that /~user1/ works in for both www.example.com and www.example2.com. logically www.example2.com should not have any users. This just brings home that www.example.com and www.example2.com are equal. I put in a UserDir in the VirtualHost container for www.example2.com as

UserDir someotherdir_thatdoesnotexist

Then www.example.com and www.example2.com returned 404. (Which is the result I was looking for.)

Therefore, I believe the Servername directive in the VirtualHost block is not being matched to the browser provided ServerName.

More detail:
I am using a LinkSys router and port forwarding 80 to the linux/apache machine. I tried DMZ'ing that machine and unport forwrding and all the results were the same.

I hope this helps. George please stay with me.

(again just to be clear I am using the config exactly as above... I mentioned a lot of changes and testing.... But, I put it all back to that one above. I believe that is the a version that will work after we find out why the browser ServerName is not matching with the container ServerName)

shortbus

8:51 pm on Sep 13, 2004 (gmt 0)

10+ Year Member



I think I have figured out that it may be the server compile settings.

It is RedHat Linux with a RPM install of Apache.

Has anyone ran into this before?

Any tips on a regular compile?

shortbus

1:41 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



Okay, I figured it out.

It was because of the NAT of the firewall.

Here is my config file:
------------------------------------------------
ServerName localhost

UseCanonicalName On

NameVirtualHost 192.168.0.1 #external address
NameVirtualHost 192.168.1.100 #internal address

<VirtualHost 192.168.1.100 192.168.0.1>
ServerName www.example.com
DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost 192.168.1.100 192.168.0.1>
ServerName www.example2.com
DocumentRoot /home/jail/home/example/html
</VirtualHost>

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

I did not recompile of anything.. I just used the config from above. (and restarted apache)

My router is set up to port forward. To the ...100 box.

I am set thanks for all the help.