homepage Welcome to WebmasterWorld Guest from 54.196.24.103
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
virtual host not working
newbie question/problem
bbxrider




msg:3282120
 8:56 pm on Mar 14, 2007 (gmt 0)

this is for apache 2.2.4 on winxp pro
below i listed my .conf directives that i think are relevant to setting up multiple virtual hosts on the same ip address. my problem is the default/index page for job1data.com is served up for both domains, try it. i get no error message when starting apache and no error logs are showing up for either domain. have tried a number of variations with no luck.

ServerRoot "C:/apache2"
Listen 80
DocumentRoot "C:/apache2/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
</Directory>
<Directory "C:/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
nameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin bbxrider@example.com
DocumentRoot "C:/apache2/htdocs/example2/"
DirectoryIndex index.html index.htm
ServerName www.example2.com
ServerAlias example2.com *.example2.com
ErrorLog C:/apache2/log/www.example2-error_log
# CustomLog C:/apache2/log/www.example2-access_log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin bbxrider@example.com
DocumentRoot "C:/apache2/htdocs/"
DirectoryIndex index.html index.htm
ServerName www.example.com
ServerAlias example.com *.example.com
ErrorLog C:/apache2/log/www.example-error_log
# CustomLog C:/apache2/log/www.example2-access_log
</VirtualHost>

[edited by: jdMorgan at 10:30 pm (utc) on Mar. 14, 2007]
[edit reason] Example.com [/edit]

 

Bluesplinter




msg:3282277
 11:35 pm on Mar 14, 2007 (gmt 0)

Dunno if this is behind your problem or not, but on my Win2K3 server, I had to set each virtual host section WITH the IP... the wildcard wouldn't work properly.

<VirtualHost 123.123.123.123:80>

With *:80, the results were unpredictable.

And welcome to Webmaster World!

[edited by: Bluesplinter at 11:36 pm (utc) on Mar. 14, 2007]

bbxrider




msg:3282310
 12:24 am on Mar 15, 2007 (gmt 0)

thanks for the reply and welcome
i tried changing all the wildcards to my ip address and still no luck
in a way i'm kinda glad it didn't work because i have a dynamic ip. the dynamic isn't that bad, my router updates automagically with ddns, and it really doesn't change that often, but it would be one more thing if i had to go make the changes also in my .conf
at first glance it looked so easy to do this, so i am thinking there must be some basic piece i have missed or messed up.

Bluesplinter




msg:3282319
 12:45 am on Mar 15, 2007 (gmt 0)

I don't know your setup, so this may sound stupid, but... which IP did you use? It sounds like you're on a home network, so the computer's IP will be different that the external IP, and Apache will need to listen on the internal IP.

Open up a dos box and type ipconfig and see what your IP is. If your router assigns you an IP, it won't be the same as your external IP. Use the internal IP (probably starting with 192. but you might also use 127.0.0.1) for the vhost setting.

If you already know all that, or I misunderstood your setup, then sorry :)

bbxrider




msg:3282330
 1:10 am on Mar 15, 2007 (gmt 0)

thanks again for the follow up reply, very perceptive, this is a home network and i tried using the local lan ip, but still no luck. again i changed all the ip's, the virtualHost as well as nameVirtualHost.

Bluesplinter




msg:3282371
 2:32 am on Mar 15, 2007 (gmt 0)

Hrmmm... I compared your conf to mine, and the only areas of interest that were different are:

1) My Listen has the full IP: Listen 123.123.123.123:80
This is because my box is also running IIS, and I have some IPs configured for IIS, and some for Apache, so I have to list the separate IPs. Probably not something that affects you, unless you also have IIS running on your box. Probability: LOW

2a) My NameVirtualHost uses IP (no port): 123.123.123.123
2b) My <VirtualHost 123.123.123.123:80>
We already discussed these, so not your problem. Probablility: NIL

3) My vhost DocumentRoot does NOT have a trailing slash. Yours do. Probability: HIGH ('cause there ain't nothin' left <g>).

So, remove the trailing slash and see if that helps. You might also try using parallel directories instead of a parent and child, ie:

DocumentRoot "C:/apache2/htdocs/example2"
DocumentRoot "C:/apache2/htdocs/example1"

I removed the trailing slashes for you :)

Also, make sure IIS is not installed (or is off). If none of this helps, you'll have to find someone smarter than me.

bbxrider




msg:3282432
 4:56 am on Mar 15, 2007 (gmt 0)

many thanks again for your thoughtful reply
unfortunately no luck with anything but there MUST be something very basic amiss with my settings. i say this because i created the parallel dirs for each domain, with unique pages for each domain and htdocs,(good debugging suggestion) and i still get served the page from htdocs! i even commented out the documentRoot directive and still get the htdocs page for both domains! i will try a few more combos as i think of them and if any thing works will post the result

Bluesplinter




msg:3282594
 10:10 am on Mar 15, 2007 (gmt 0)

It sounds like neither of your vhosts are being used... just your default setup. Try this for the main docroot:

DocumentRoot "d:/apache2/htdocs/default"

And for the two vhosts:

DocumentRoot "d:/apache2/htdocs/example1"
DocumentRoot "d:/apache2/htdocs/example2"

IOW, put them in separate branches of the tree. Also, you didn't list your default NameVirtualHost setup... do you have one? Mine looks similiar to this:

# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost 123.123.123.123:80>
ServerAdmin me@example.com
DocumentRoot "D:/Apache2/htdocs/default"
ErrorLog logs/dummy-host-error_log
CustomLog logs/dummy-host-access_log common
</VirtualHost>

It comes before any of the "real" vhost blocks. Try these suggestions, restart Apache, and see which directory actually feeds the requests.

bbxrider




msg:3282928
 5:04 pm on Mar 15, 2007 (gmt 0)

many thanks again for sticking with this

this is my current setup, at least as far as directives for virtual host
i tried the DocumentRoot "C:/apache2/htdocs/default" and got an error msg on the restart that it must be a directory

ServerRoot "C:/apache2"
Listen 80
DocumentRoot "C:/apache2/htdocs"
<Directory "C:/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin bbxrider@example.com
DocumentRoot C:/apache2/htdocs/example2
DirectoryIndex index.html index.htm
ServerName www.example2.com
ServerAlias example2.com *.example2.com
ErrorLog C:/apache2/log/www.example2-error_log
# CustomLog C:/apache2/log/www.example2-access_log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin bbxrider@example.com
DocumentRoot C:/apache2/htdocs/example
DirectoryIndex index.html index.htm
ServerName www.example.com
ServerAlias example.com *.example.com
ErrorLog C:/apache2/log/www.example-error_log
# CustomLog C:/apache2/log/www.example2-access_log
</VirtualHost>

i ran the httpd -S -w for the status of the current virt host setup, it looks ok to me:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server www.example2.com (C:/apache2/conf/httpd.conf:228)
port 80 namevhost www.example2.com (C:/apache2/conf/httpd.conf:228)
port 80 namevhost www.example.com (C:/apache2/conf/httpd.conf:237)
Syntax OK

what i find really strange is that if apache has my default server being example2, how come i get the htdocs directory default page for example2.com and not the example2.com default page?

[edited by: jdMorgan at 3:54 pm (utc) on Mar. 16, 2007]
[edit reason] No URLs, please. See Terms of Service. [/edit]

bbxrider




msg:3283987
 4:35 pm on Mar 16, 2007 (gmt 0)

well good news, problem solved, strange and another small typo that ruined things. evidently it was a bad path statement for the virt host error logs, i had log instead of logs in the path, ie, C:/apache2/log/.., instead of C:/apache2/logs/... once i changed that everything worked fine.
so a dumb mistake that just went unnoticed for a long time.
i still find it strange that apache didn't complain about the bad path on a start like it did when i had tried DocumentRoot "C:/apache2/htdocs/default", and that the status from httpd -S and -f indicated no problems. a warning on the start that i had a bad path statement would have pointed right to the problem.
but whatever, it works now, and thanks again for all the replies
bbxrider

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved