LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-11-2006, 04:47 AM   #1
icejam
LQ Newbie
 
Registered: Apr 2006
Distribution: RHEL4, FC4
Posts: 7

Rep: Reputation: 0
Red face Virtual Host conflict with DocumentRoot


Hi all,
Having serious trouble using Virtual Host.
I'm having ServerName as and DocumentRoot as
Code:
ServerName mydomain1.com:80
DocumentRoot "/var/www/html"
and have:
Code:
NameVirtualHost *:80

<VirtualHost *:80>
ServerName mydomain2.com
DocumentRoot /home/SCI
</VirtualHost>
all other codes are in default.

I have both index.html in /var/www/html/temp1/ and /home/SCI/temp2/

when I go to mydomain1.com/temp1/ it didn't work but mydomain2.com/temp2/ worked fine with the above settings.

but if I added a "s" behind the http temp1 worked prefectly. (Which I'm very confused..., I do have cgi-bin script set up though but I believe there's nothing to do with the settings inside)

When I comment out the
Code:
DocumentRoot /home/SCI
under VirtualHost this time mydomain2.com/temp2 worked but not mydomain1.temp1

Can any one help this dummy?
Cheers
Jam
 
Old 04-11-2006, 08:31 AM   #2
rahulk
Member
 
Registered: Mar 2006
Posts: 110

Rep: Reputation: 16
can you add another VirtualHost entry as following

NameVirtualHost *:80

<VirtualHost *:80>
ServerName mydomain2.com
DocumentRoot /home/SCI
</VirtualHost>

<VirtualHost *>
ServerName mydomain1.com
DocumentRoot /var/www/html
</VirtualHost>


then you will be able to work out with the ServerName!!

see the idea is like following:-

ServerName mydomain1.com:80

is used by the server to identify the itself on DNS

If you are using name-based virtual hosts, the ServerName inside a <VirtualHost> section specifies what hostname must appear in the request's Host: header to match this virtual host. hence you need to put the virtualhost entry for ServerName to make it appear valid on DNS lookup for incoming request.

-Rahul.
 
Old 04-11-2006, 08:51 AM   #3
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
If you use virtual hosts then the documentroot in the global context is ignored. You must do as rahulk says. Another thing to note is that the first virtual host found in the config file is the default one, that is, if a domain points to your server but there is no virtual host for it then the documents from the first virtual host will be used. With this knowledge you may find it more appropriate to swap the order of the virtualhost clauses around in rahulk's example
 
Old 04-11-2006, 08:01 PM   #4
icejam
LQ Newbie
 
Registered: Apr 2006
Distribution: RHEL4, FC4
Posts: 7

Original Poster
Rep: Reputation: 0
Thank you rahulk and phil.d.g, the combination of your answers worked great on my server (except I had to change <VirtualHost *> to <VirtualHost *:80> for mydomain1.com but it worked)
I don't know what to do without you guys. (those apache books didn't even mention the global context is ignored while having virtual hosts)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
virtual users and virtual host need to stay at /home nephish Linux - Networking 3 01-14-2006 02:36 PM
Virtual Host abridge Linux - Software 1 04-13-2005 08:35 AM
virtual host ziggie216 Linux - General 2 12-22-2003 07:38 PM
Virtual Host |Drakehash| Linux - Networking 0 07-17-2003 04:02 PM
VIrtual host thep Linux - General 10 08-06-2002 12:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration