PDA

View Full Version : virtual hosts with apache fc4



thephydeaux
15th July 2006, 05:35 PM
Hi Guys

I'm trying to set up virtual hosts with apache on my fc4 box. My apologies for the longish post, but this is what I've tried. Ive mostly just played with document root and server name, in the hope that if I can get them right, then I can go on to alias etc.

NameVirtualHost staticip

<VirtualHost staticip>
DocumentRoot //var/www/html
ServerName domain1

# Other directives here

</VirtualHost>

<VirtualHost staticip>
DocumentRoot //var/www/folder/html
ServerName domain2

# Other directives here

</VirtualHost>

This gets the index page from domain1 loading all the time, ie from the url for domain 1 and the url from dommain2.

So, I tried this for domain 2

NameVirtualHost staticip

# Virtual host domain2
<VirtualHost static ip>
DocumentRoot /var/www/folder/html
ServerName domain2
DirectoryIndex index.html index.htm index.shtml
</VirtualHost>

Same result, so I tried this for domain 1 to try to separate it from domain 2

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www/folder
ServerName domain1
# other directives here
</VirtualHost>

and this:

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www/folder/html
ServerName domain1
# other directives here
</VirtualHost>

and get this error when I try to re-start apache

Failed to start apache :
Starting httpd: Syntax error on line 348 of /etc/httpd/conf/httpd.conf:
DocumentRoot must be a directory
[FAILED]

Of course, while playing with this I have been re-starting apache with each attempt, and where necessary, moving the files from folder to folder. I have tried altering the config file directly and through webmin,, all to no avail. Its getting very frustrating as I&#39;m going around in circles and re-trying things that didnt work before. Any clues as to what I&#39;&#39;m doing wrong, as I am obviously doing something (or many things, arse about)

Thanks guys

Tim R

purana
15th July 2006, 05:40 PM
So if I understand correctly, you want domain1 to be served from /var/www/domain1 and domain2 to be served from /var/www/domain2 (for example)

But each time you try, the page for domain1 is loading for each of the 2 domains when you connect (ie. its not serving correctly?

EDIT: for reference, my default server that is served from /var/www uses the following;



NameVirtualHost *
&#60;VirtualHost *&#62;
ServerName homer.heimic.net
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
&#60;Directory /&#62;
Options FollowSymLinks
AllowOverride None
&#60;/Directory&#62;
&#60;Directory /var/www/&#62;
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2&#39;s default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/&#036; /apache2-default/
&#60;/Directory&#62;
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
&#60;Directory &#34;/usr/lib/cgi-bin&#34;&#62;
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
&#60;/Directory&#62;

ErrorLog /var/log/apache2/error.log

# Possible values include&#58; debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
ServerSignature On

&#60;/VirtualHost&#62;


And then my first virtual host is served from /home/httpd/virtuals/heimic.net/home via the following;



&#60;VirtualHost *&#62;
ServerName home.heimic.net
ServerAdmin webmaster@home.heimic.net

DocumentRoot /home/httpd/virtuals/heimic.net/home/
&#60;Directory /&#62;
Options FollowSymLinks
AllowOverride None
&#60;/Directory&#62;
&#60;Directory /home/httpd/virtuals/heimic.net/home/&#62;
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2&#39;s default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/&#036; /apache2-default/
&#60;/Directory&#62;

&#60;Directory /home/httpd/virtuals/heimic.net/home/gallery&#62;
AllowOverride Options FileInfo
&#60;/Directory&#62;

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
&#60;Directory &#34;/usr/lib/cgi-bin&#34;&#62;
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
&#60;/Directory&#62;

ErrorLog /var/log/apache2/virt-home-error.log

# Possible values include&#58; debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/virt-home-access.log combined
ServerSignature On

&#60;/VirtualHost&#62;

thephydeaux
15th July 2006, 05:41 PM
Thanks

Yes, thats what I want to do

TR

purana
15th July 2006, 05:46 PM
See my edit post above.

It works as I mentioned in my post. And dupe the virtual as many times as you want for your virtual hosting needs. And they will serve correctly and wont affect the main webserving :)

thephydeaux
15th July 2006, 07:01 PM
Thanks for that

I tried an edit of your file on my server and now get the error that httpd failed to start. I thought that it might be a problem with the Listen command, so I tried

Listen *:80
Listen 192.168.1.2:80
Listen 58.6.119.8:80

but still get the same error

Thanks for your time

Tim R

thorevenge
15th July 2006, 07:05 PM
Don&#39;t forget things like editing the hosts file.

Dave once posted a really good link about VirtualHosts to me once, I will see if I can dig it up.

Cheers

Edit: Quick google revealed http://www.macdave.us/chronicles/

You will find his trials there

BiRDBRAiN
15th July 2006, 08:16 PM
This is probably obvious, but try having a look at the error.log files, you might get a bit more of an exact clue as to what is going wrong.

Also, another obvious thing, but must be asked, are you sure the two domains resolve to the IP that is in your NameVirtualHost directive?

thephydeaux
16th July 2006, 07:23 AM
Thanks guys

Still havent managed to get it to work. Its got me stumped.

Tim R