Forum Moderators: phranque
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]
NameVirtualHost 111.111.111.111:80<VirtualHost 111.111.111.111:80>
(other directives here)
</VirtualHost>
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
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
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.
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 :-)
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?
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
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!
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!
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.