Forum Moderators: phranque

Message Too Old, No Replies

Name Based Virtual Hosts with Apache 2 / Mandrake ADVX

I have a problem with virtual host configuration in apache2

         

TheGreen

3:07 am on Mar 17, 2005 (gmt 0)

10+ Year Member



Hello. I am new to this forum. Please forgive my question, I have not found the answer by seraching here, though I did see similar questions.

I am having dificulty with named virtual hosts. Using Mandrake 10.0 official, with ADVX apache (apache 2), I also have two test servers with Mandrake 10.1 and ADVX apache. I have searched and read quite a lot of posts here and elswehere and tried many of the suggestions. I have read and followed the doc at apache.org for 2.0 Virtual host, and I have read the included ADVX docs. I am obviously missing something.

When I go to www.domain.com I get the correct site. When I go to test.domain.com I get the www.domain.com site, not the page I have for test. If I go to www.domain.com/test I do get the correct test index page.

If I understand correctly in Apache 2 / ADVX we have httpd.conf, which can include additional config files such as Vhosts.conf. So far I get it. Makes sense too.

So I include Vhosts.conf in httpd.conf, and set up my virtual hosts in Vhosts.conf. Ok. But it doesnt work. I have tried many things. I only have one IP address, and I would like to have:

www.domain.com

test.domain.com

example.domain.com

etc.

I had this same setup in apache 1.3 and it worked well for me.

Below I have listed my basic settings, and listed the issue I am having:

in /etc/httpd/conf/httpd.conf I have:

Include conf/vhosts/Vhosts.conf

in /etc/httpd/conf/vhost/Vhosts.conf I have:

NameVirtualHost 111.111.111.111:*

NameVirtualHost 111.111.111.111

<VirtualHost 111.111.111.111:80>

DocumentRoot /www/html

ServerName www.domain.com

ServerPath /www.domain.com

</VirtualHost>

<VirtualHost 111.111.111.111:80>

DocumentRoot /www/html/test

ServerName test.domain.com

ServerPath /test.domain.com

</VirtualHost>

I have also played with the Directory directives in commonhttpd.conf they are :

<Directory /var/www/html>

Options -All -Multiviews

AllowOverride None

<IfModule mod_access.c>

Order deny,allow

allow from all

</IfModule>

</Directory>

Alias /test /var/www/html/test

<Directory /var/www/html/test>

AllowOverride All

Options Indexes FollowSymLinks MultiViews

Options -All -Multiviews

AllowOverride None

<IfModule mod_access.c>

Order deny,allow

allow from all

</IfModule>

</Directory>

The IP and domain I use are correct, I just used ones and domain here for example.

I have been stuggling with this for quite a while, and now am up against a project deadline. I guess I can go back to apache 1.3, but I would sure like to make this work. <snip>

[edited by: jdMorgan at 5:43 am (utc) on Mar. 17, 2005]
[edit reason] Edited to comply with TOS. [/edit]

sitz

5:54 am on Mar 17, 2005 (gmt 0)

10+ Year Member



Just off the cuff, if accessing all websites you've configured in your httpd.conf returns the content for the first one, chances are they're not configured correctly; if apache can't find a VirtualHost for the hostname you're trying to reach, it will use the first one listed. At a guess (I've not tested this), this is (in your case) being caused by the fact that your NameVirtualHost directives don't match the text you're using in your VirtualHost blocks ('NameVirtualHost 111.111.111.111:*' is not the same as 'VirtualHost 111.111.111.111'). Try something like:

NameVirtualHost 111.111.111.111:80

<VirtualHost 111.111.111.111:80>
(other directives here)
</VirtualHost>


and see if that works any better. Don't forget to bounce apache after making the changes. ;)

TheGreen

12:41 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



sitz,

Thanks for the info. That is in fact waht happens, I always go to the defualt site. I tried your suggestion but it did not change the problem. Normally I just do *:80 but that doesnt work either. I know its me, because I have the same problem on two different servers. Something in either apache 2 or Mandrakes ADVX version of Apache 2 I do not understand, YET. :-)

Also if I run httpd2 -S I get:

# httpd2 -S
[Thu Mar 17 06:28:56 2005] [warn] NameVirtualHost 65.116.87.245:0 has no VirtualHosts
VirtualHost configuration:
Syntax OK

hmmm. So I would say that is my issue. How do I fix that?

Thanks again,

Steve

sitz

1:38 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



That error isn't a problem unless the NameVirtualHost mentioned in the log entry is the only NameVirtualHost you have configured. If it *is* the only NameVirtualHost block, then it means your VirtualHost blocks don't match the NameVirtualHost block. Like I said. =)

Is it possible that the Include'd vhosts.conf file isn't even being brought into the configuration? Easy way to test is to place an invalid directive in the vhosts.conf file and try and restart Apache. Another way is to run the apache2 binary (not the ctl script) on the commandline with the -X argument, under strace (linux) or truss (solaris):


strace -f -ostrace.out /path/to/apache2-binary -f /path/to/httpd.conf -X


truss -f -otruss.out /path/to/apache2-binary -f /path/to/httpd.conf -X

...let it sit there for a few seconds, and then ^C. grep the outfile for your vhosts config file; if it's not there, its not being opened, and you may have the path to it wrong in your httpd.conf.

encyclo

2:19 pm on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], TheGreen.

I use an earlier version of ADVX on my test machine. I've got it set up as follows in my Vhosts.conf:

# 
# First Virtual Host denies access to anyone
# asking for a non-existant VH. Then, VHs specified.
#
NameVirtualHost *
<VirtualHost *>
ServerName default.only
<Location />
Order allow,deny
Deny from all
</Location>
</VirtualHost>
<VirtualHost *>
DocumentRoot "/path/to/dir"
ServerName test.example.com
</VirtualHost>
<VirtualHost *>
DocumentRoot "/path/to/otherdir"
ServerName test2.example.org
</VirtualHost>
<VirtualHost *>
DocumentRoot "/path/to/thirddir"
ServerName widgets.example.net
</VirtualHost>

As I understand it, you don't need to specify the IP address unless you have several and are using IP-based virtual hosts. Also, I run everything via virtual hosts, with nothing as the default: ie. nothing is available if you visit via the IP address only except a 403 Forbidden. You can remove the

default.only
rule if you don't want that.

TheGreen

3:47 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



sitz,

Thank you I will try this. I know vhost is getting called, because I put garbage in there and it errored. I will try the other suggestion and report back.

TheGreen

3:53 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



encyclo...

Thanks, its nice to know someone here is also using ADVX. I used your config, I still have same problem. Here is the strange part.

I use webmin, (I will next do all this via ssh to make sure its not webmin)

Webmin always shows a default server that handles all requests that are not specifically resolved. I cant seem to get rid of this server, and it is not in my configs.

Using your config, I should not be able to go to my main site via ip address only correct? Well I still can :-) so that default server that shows in my webmin cp must be the problem. Here is what I have based on your config:

#
# First Virtual Host denies access to anyone
# asking for a non-existant VH. Then, VHs specified.
#
NameVirtualHost *
<VirtualHost *>
ServerName default.only
<Location />
Order allow,deny
Deny from all
</Location>
</VirtualHost>
<VirtualHost *>
DocumentRoot "/var/www/html"
ServerName schnizits.com
</VirtualHost>
<VirtualHost *>
DocumentRoot "/var/www/html/test"
ServerName test.schnizits.com
</VirtualHost>

# <VirtualHost *>
# DocumentRoot "/path/to/thirddir"
# ServerName widgets.example.net
# </VirtualHost>

I left the third one there, cause I have a production server that I need to set up several vhosts for, so if it works on this server I will move it to my production server and add the other hosts.

so if I go to [ip...] address I get my home page
if I go to www.schnizits.com I get my home page
if I go to [test.schnizits.com...] I get my home page

I will try waht sitz reccomended next.
Thanks for your patience guys, I am a networking / infrastructure guy, and some of this is a little over my head.... for now :-)

TheGreen

4:00 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



sitz,

is this what you meant? I tried and got error:

# strace -f -ostrace.out /usr/sbin/httpd2 -f /etc/httpd/conf/htt
pd.conf -X
Syntax error on line 22 of /etc/httpd/conf/httpd.conf:
Cannot load /etc/httpd/modules/mod_env.so into server: /etc/httpd/modules/mod_env.so: undefined symbol: ap_palloc

is that my problem?

wheel

4:26 pm on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm running mandrake with apache2, here's a snippet from my Vhosts.conf file:

NameVirtualServer *
<VirtualHost *>
ServerName www.domain1.com
ServerAlias domain1.com
DocumentRoot /home/path-to-site/
CustomLog /home/pathtologfile combined
DirectoryIndex index.php index.html
ErrorDocument 404 /redirect.php
</VirtualHost>

<VirtualHost *>
ServerName www.domain2.com
ServerAlias domain2.com
DocumentRoot /home/pathtodomain2/
CustomLog /home/pathtologfile combined
DirectoryIndex index.php index.html
</VirtualHost>
---
so to make the subdomain work, I'd just add:
<VirtualHost *>
ServerName subdomain.domain2.com
DocumentRoot /home/pathtoSUBdomain2/
CustomLog /home/pathtologfile combined
DirectoryIndex index.php index.html
</VirtualHost>

Then restart apache. Of course, you also need to make sure that you have DNS set up to point the subdomain to your IP address.

hth

TheGreen

11:28 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



encyclo...

For grins I just put the config you gave me on a test box and it works perfectly. So THANK YOU to all of you for your help. The reason it is not working on my production server? I dont know, the difference is my production server is Mandrake 10.0 with ADVX / apache 2.048 and uses httpd.conf,

My test is Mandrake 10.1 with ADVX / Apache 2.050 and uses httpd2.conf. I dont get it, but at least I know I can get it to work. I am so glad I found this forums, and will try to contribute back. Thanks!

TheGreen

7:13 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Hi again from TheGreen.

thanks to all the great advice I have some of my virtual hosts working.... BUT

The default.server deny thing works, but maybe to good.

I have dns set up for:

domain.com
www.domain.com
subdomain1.domain.com
subdomain2.domain.com

I can get to [domain.com,...] as well as www.domain.com

i had to a a virtual host for each server name, domain.com and www.domain.com otherwise www.domain.com gave me the 404 error. now those work well. BUT I cannot get subdomain1.domain.com or subdomain2.com to work. they just get 404 errors. do I need to add a virtual host for http:// for each one like I had to with www. I also had to change the NameVirtualHost from * to *:80 because I have ssl running. eventuall the subdomains wil need ssl.

Can anyone help me with why I get 404 on subdomain.domain.com?

Thanks all!

TheGreen

7:15 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Oh I just found out that:

browsing to [subdomain.domain.com...] gives me 404 error, BUT browsing to [subdomain.domain.com...] lets me see my page? I have the vhost set up as *:80, why would it be answering to 443 ssl and not 80?

Thanks.

TheGreen

10:57 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Dang, I'm an idiot. Got it all fixed. Thanks again all!

(www/subdomain when really is should have been ww/html/subdomain)