Apache Server configuration support - NameVirtualHost Problems

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > May 2006 > NameVirtualHost Problems





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author NameVirtualHost Problems
Scooter

2006-05-22, 1:16 pm

I have the following configuration directives in my httpd.conf

NameVirtualHost 1.2.3.4
<VirtualHost host1.thiscompany.com>
ServerName host1.thiscompany.com
DocumentRoot /www/host1.thiscompany.com
</VirtualHost>

<VirtualHost host2.thiscompany.com>
ServerName host2.thiscompany.com
DocumentRoot /www/host2.thiscompany.com
</VirtualHost>

>From everything I read this should be correct...but its not working.

Hits to my sites pick up the default document directory. I have added
the %v to my LogFormat so that I will get the hostname that I am
hitting. In the log instead of seeing host1.thiscompany.com, I get the
actual name of my server,
"server1.thisregion.thisbuilding.thiscompany.com". So, as just a fluke
I put "1.2.3.4 host1.thiscompany.com" in the hosts file of my
apache server. And it started working, my hits to
"host1.thiscompany.com" were served correctly. Is apache trying to do
some type of IP resolution itself? Why would I have to put my hosts in
my Apache servers hosts file?

Confused.

Davide Bianchi

2006-05-22, 1:16 pm

On 2006-05-22, Scooter <slbentley@cox.net> wrote:
> I have the following configuration directives in my httpd.conf
>
> NameVirtualHost 1.2.3.4
><VirtualHost host1.thiscompany.com>


If you are using NAME based virtual host, and unless you want to separate
different IPs/vhosts, use a '*', not the IP address and not the
server name:

NameVirtualHost *

<VirtualHost *>
ServerName ...

> DocumentRoot /www/host1.thiscompany.com


Usually you add more directives after this, like the standard options
for the DocumentRoot.

> Hits to my sites pick up the default document directory.


How are you trying to connect to the server? Is the VHost name resolved
in the correct IP address? What apachectl configtest says? Did you restarted
Apache after changing the configuration file?

> "host1.thiscompany.com" were served correctly. Is apache trying to do
> some type of IP resolution itself?


Yes, to respond to clients with an hostname and not with an IP
address.

Davide

--
What are YOU doing to oppose the Microsoft Juggernaut?
Scooter

2006-05-22, 1:16 pm

Well its possible when its all said and done that I will only be using
one IP address on this configuration, but at the moment some of the
hosts are using SSL. Those that dont I would like to bind to a single
IP, hence the IP vs the *.

The IP is correct but not in DNS, I'm testing from my local workstation
with the IP in MY hosts file, and yes, I restarted apache after making
my config changes.

In reference to your last comment, that yes Apache is trying to do
resolution, this confuses me. I'm using the IP based NameVirtualHost
host and then subdividing the request on a name. Why would apache need
to look anything up?

Config test is coming back as OK

Davide Bianchi

2006-05-22, 1:16 pm

On 2006-05-22, Scooter <slbentley@cox.net> wrote:
> Well its possible when its all said and done that I will only be using
> one IP address on this configuration, but at the moment some of the
> hosts are using SSL. Those that dont I would like to bind to a single
> IP, hence the IP vs the *.


Ok, still, you should use the same in the NameVirtualHost and in the
various VirtualHosts blocks, so if you use the IP in the first, you
have to use the IP in the others.

> resolution, this confuses me. I'm using the IP based NameVirtualHost
> host and then subdividing the request on a name. Why would apache need
> to look anything up?


The default working in Apache is to lookup the 'default' VirtualHost
using gethostbyip, that try to do a reverse-lookup of the IP address.

> Config test is coming back as OK


Then the problem is that the VirtualHost configuration is not looked up.
Can you post the whole config file?

Davide

--
The only truly safe "embedded system" is the system that has
an axe embedded in it... --Tanuki
Scooter

2006-05-22, 1:16 pm

So are you saying it should look like:

NameVirtualHost 1.2.3.4
<VirtualHost host1.domain.com>
....
</VirtualHost>

NameVirtualHost 1.2.3.4
<VirtualHost host2.domain.com>
....
</VirtualHost>

or am I misunderstanding? I think I'm getting myself more confused all
the time.

Davide Bianchi

2006-05-22, 1:16 pm

On 2006-05-22, Scooter <slbentley@cox.net> wrote:
> So are you saying it should look like:
>
> NameVirtualHost 1.2.3.4
><VirtualHost host1.domain.com>
> ...
></VirtualHost>
>
> NameVirtualHost 1.2.3.4
><VirtualHost host2.domain.com>
> ...
></VirtualHost>


Nope

NameVirtualHost 1.2.3.4
<VirtualHost 1.2.3.4>
ServerName host1.domain.com
....
</VirtualHost>

<VirtualHost 1.2.3.4>
ServerName host2.domain.com
...
</VirtualHost>

....

Note: I think that the documentation about virtual host on
http://httpd.apache.org is quite clear, have you tried reading it?

Davide

--
It's Mickeysoft for pity's sake. *OF COURSE* it's going take all the ram
in range. I'm surprised the fsking box doesn't grow tentacles and start
stealing DIMMs from the machines next to it.
-- JoeB
Scooter

2006-05-25, 1:25 am

I not only tried to read the documentation, I succeeded. I also read my
O'Reilly book "Apache: The Definitive Guide". And in doing so I came to
use the configuration you have listed here. That was how I configured
it at first.. I first tried with one NameVirtualHost with 2 VirtualHost
groups under it like you have listed. Didn't work. Then I attempted to
put the NameVirtualHost above each VirtulHost, and that didn't work
either. I thought maybe it would work because I've seen webmin and some
other web based configuration utilities do this...but I typically try
to avoid those. Oh and I do have the ServerName directive in my
VirtualHost stanzas. The only way I could get it to work was to put the
hostnames in the apache servers host file. Just seems rather cheesey to
have to do that. But if I have to I have to I guess.

Scooter

2006-05-25, 1:25 am

I'm not too proud to admit when I'm wrong. I'm going to put this
blindfold on now and let you get your aim all ready

In my old age I failed to notice your VirtualHost was IP and not name
based. So switching my VirtualHost to the config you have did work
after all. My apologies. But I am going to put the blame on O'Reilly. I
was using the config I found on the bottom of page 61 in my Definitive
Guide, 2nd edition. I think once I got hung up on their config example
I was blinded to anything else I saw.

Thanks so much for your assistance.

Davide Bianchi

2006-05-25, 1:25 am

On 2006-05-24, Scooter <slbentley@cox.net> wrote:
> based. So switching my VirtualHost to the config you have did work
> after all. My apologies. But I am going to put the blame on O'Reilly.


If it does work, then it's ok.
Davide

--
Blackmail Error:
Send $200 to Bill Gates or your computer will get so messed up it will never
work again.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com