LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-12-2004, 03:56 PM   #1
oO_SwooP_Oo
LQ Newbie
 
Registered: Sep 2003
Posts: 8

Rep: Reputation: 0
Sub Domains & Virtual Hosts [Closed - Unsolved]


I'm running Apache 2.0.51 r1 on a Gentoo Linux box ver 2.4.25 and what I would like to do is host individual websites for some user accounts using sub-domains (ex. foo.somesite.sytes.net for user foo). My No-IP account is upgraded to Enhanced.

At the moment, foo's website can be accessed through the default per-user directory somesite.sytes.net/~foo/ and the default website is simply accessed at somesite.sytes.net.

This is what I have done so far:

- I have enabled wildcards for the domain somesite.sytes.net (which is port redirected to 81)

- In the commonapache.conf file (located in /etc/apache2/conf) I have added the following for virtual hosting:

Code:
NameVirtualHost *
<VirtualHost *>
    ServerName www.somesite.sytes.net
    ServerAlias somesite.sytes.net
    DocumentRoot /http/default
</VirtualHost>
<VirtualHost *>
    ServerName foo,somesite.sytes.net
    DocumentRoot /http/foo/public_html
</VirtualHost>
I restarted the server and when I type foo.somesite.sytes.net I am redirected to the default document rather than foo's site. I tried switching the order of the virtual host directive blocks, and sure enough I get to foo's site, but then accessing the www.somesite.sytes.net server alias or just somesite.sytes.net also takes me to foo's site. From my observations, even with the host specific server names (www vs. foo) the virtual host configuration used is defaulted to whatever is listed first.

I've looked around in various linux forums and the apache website to figure out how to fix this and obtain the results that I am looking for, but as far as I know, everything I've done is correct. But since I am not getting the result I want, something must be wrong. Please help, I've spent so much time already on this. Thanks.

Last edited by oO_SwooP_Oo; 10-15-2004 at 12:26 PM.
 
Old 10-12-2004, 08:56 PM   #2
oO_SwooP_Oo
LQ Newbie
 
Registered: Sep 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Ugh, after 3 hours, still nothing!! :x

Other information that could prove useful in troubleshooting:

- In apache2.conf ServerName is set to somesites.sytes.net

- In commonapache.conf I switched the UseCanonicalName Off

- In my /etc/hosts file I added
192.168.0.1 www.somesites.sytes.net
192.168.0.1 foo.somesites.sytes.net

Any ideas?
 
Old 10-12-2004, 10:32 PM   #3
viniosity
Member
 
Registered: Oct 2001
Location: Washington, DC
Distribution: Debian, Archlinux, Ubuntu, Sidux
Posts: 244

Rep: Reputation: 30
Virtual hosts can be a real PIA sometimes. I've had instances where the wildcard didn't' work and I'd have to use the IP. For instance:

<VirtualHost 192.168.1.12>
ServerName www.foo.com
DocumentRoot /var/www/foo
</VirtualHost>

Here is a paste from my /usr/local/apache2/conf/httpd.conf file:

<VirtualHost *>
ServerName www.foo.com
ServerAlias foo.com
ServerPath /foo/
DocumentRoot /usr/local/foo
ErrorLog logs/foo.com-error_log
</VirtualHost>


Also, I generally use bind instead of messing with the hosts file. You might be able to test your config with the IP. For instance 192.168.1.12 would resolve differently than 192.168.1.12/foo/

Another hint is to run apachectl configtest. It might point you at any errors in your conf file.
 
Old 10-13-2004, 06:36 PM   #4
oO_SwooP_Oo
LQ Newbie
 
Registered: Sep 2003
Posts: 8

Original Poster
Rep: Reputation: 0
I've tried both the * and explicit ip address and neither one made a difference. Also, apache2clt showed that there were no syntax errors.

Further investigation lead me to try to figure out what the request header was sending to figure out why no match to any of the virtual host names was occuring (thus resulting in the default host serving the pages).

I started with the access_log and found that the referrer address was blank on every access to the subdomain. Is this how it should be?

Code:
192.168.0.2 - - [13/Oct/2004:17:31:51 +0000] "GET / HTTP/1.1" 200 142 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
why am I getting "-" when I type foo.somesite.sytes.net? Shouldn't the referrer portion of the log contain the address entered by the client?

If I can figure out why this is occuring (if it is not normal) then maybe this can help me to figure out the virtual host matching problem. Anyone have any ideas?
 
Old 10-13-2004, 07:42 PM   #5
oO_SwooP_Oo
LQ Newbie
 
Registered: Sep 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Disregard my last post. The dash "-" in the log where the referer is supposed to be is because there was no referer since the browser got the URL directly. The original problem still persists.
 
Old 10-14-2004, 02:38 AM   #6
oO_SwooP_Oo
LQ Newbie
 
Registered: Sep 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Some peculiar results to note:

Code:
NameVirtualHost * 
<VirtualHost *> 
    ServerName www.somesite.sytes.net 
    ServerAlias somesite.sytes.net 
    DocumentRoot /http/default 
</VirtualHost> 
NameVirtualHost 192.168.0.1
<VirtualHost 192.168.0.1> 
    ServerName foo.somesite.sytes.net 
    DocumentRoot /http/foo/public_html 
</VirtualHost>
When I accessed any of the sites (i.e. www.somesite.sytes.net, somesite.sytes.net, foo.somesite.sytes.net) the document for foo.somesite.sytes.net was served, and the other virtual host block was bypassed altogether. Either all of the subdomains are matching the second virtual host block or the first block is being ignored altogether.

I'm gonna keep playing around with this to see what's really going on.

Does anyone have any thoughts on this?
 
Old 10-14-2004, 09:53 AM   #7
viniosity
Member
 
Registered: Oct 2001
Location: Washington, DC
Distribution: Debian, Archlinux, Ubuntu, Sidux
Posts: 244

Rep: Reputation: 30
Well, I'm curious to whether the subdomain and the domain resolve from the local machine and any remote machines you might be trying. Does ping work?

ping www.somsite.sytes.net
ping www.sytes.net

Also, since you mentioned port 81 try changing your NameVirtualHost to your IP:Port e.g.

NameVirtualHost 192.168.0.2:81
 
Old 10-14-2004, 02:25 PM   #8
oO_SwooP_Oo
LQ Newbie
 
Registered: Sep 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by viniosity
Well, I'm curious to whether the subdomain and the domain resolve from the local machine and any remote machines you might be trying. Does ping work?

ping www.somsite.sytes.net
ping www.sytes.net

Also, since you mentioned port 81 try changing your NameVirtualHost to your IP:Port e.g.

NameVirtualHost 192.168.0.2:81
1) Yes the names are resolving and I am getting ICMP responses from the pings of the subdomains

2)

Code:
NameVirtualHost 192.168.0.1:81
<VirtualHost 192.168.0.1:81> 
    ServerName www.somesite.sytes.net 
    ServerAlias somesite.sytes.net 
    DocumentRoot /http/default 
</VirtualHost> 
<VirtualHost 192.168.0.1:81> 
    ServerName foo.somesite.sytes.net 
    DocumentRoot /http/foo/public_html 
</VirtualHost>
Results in the original problem still, where the subdomain foo.somesite.sytes.net is served the configuration of the first VirtualHost block

Problem still persists
 
Old 10-14-2004, 03:00 PM   #9
viniosity
Member
 
Registered: Oct 2001
Location: Washington, DC
Distribution: Debian, Archlinux, Ubuntu, Sidux
Posts: 244

Rep: Reputation: 30
I'm sorry I'm not an expert at this.. I usually get mine working by doing a lot of tinkering and a lot of apache restarting in between. The only other thing I can think of is evening it up a bit between the two by having the same entries (e.g. ServerAlias, ServerPath, etc)

Maybe somebody else from the community can help out. (
 
Old 10-14-2004, 04:29 PM   #10
oO_SwooP_Oo
LQ Newbie
 
Registered: Sep 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Revelation!

K i modified my apache configuration to display for me the host header used for the virtual host matching and my logs reveal that it is always my ip and port regardless of what subdomain the client requests (ex. foo.somesite.sytes.net, www.somesite.sytes.net, etc.). Ideally, if the client types foo.somesite.sytes.net, that is what should be in the host header so that the virtualhost matching correctly serves the right page. But somehow, the port redirection is translating foo.somesite.sytes.net to my IP in the host header.

Is there a way to preserve the subdomain information in the host header and still use port redirection so that virtual hosting will work?

Problem still persists

Last edited by oO_SwooP_Oo; 10-14-2004 at 05:51 PM.
 
Old 10-15-2004, 12:26 PM   #11
oO_SwooP_Oo
LQ Newbie
 
Registered: Sep 2003
Posts: 8

Original Poster
Rep: Reputation: 0
I'm not getting a lot of luv from the community on solving this problem so i'm just gonna give up and close this thread. If you have any insight please feel free to contribute your posts
 
Old 09-21-2005, 02:07 PM   #12
lemynshij
LQ Newbie
 
Registered: Sep 2005
Posts: 1

Rep: Reputation: 0
I've been having this same problem where the only way i can get my three virtual name based hosts to work is to have the ordering like so:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName mpi.televisiontakeover.com
DocumentRoot /usr/www/mpi
</VirtualHost>

<VirtualHost *:80>
ServerName speech.televisiontakeover.com
DocumentRoot /usr/www/speech
</VirtualHost>

<VirtualHost *:80>
ServerName www.televisiontakeover.com
DocumentRoot /usr/www/takeover
</VirtualHost>

any other ordering doesn't work.

What should i do?
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
apache2 & tomcat5 - how to configure VIRTUAL HOSTS & JSP? nicolasdiogo Suse/Novell 2 04-05-2007 09:06 AM
SuSE 9.2 - apache2 & tomcat5 - how to configure VIRTUAL HOSTS & JSP? nicolasdiogo Linux - Networking 2 03-20-2005 08:06 AM
qmail & virtual domains monacoflasher Fedora 1 06-07-2004 11:36 AM
Apache 2 & Multiple Virtual Hosts hegele Linux - Networking 4 02-21-2004 06:41 PM
MDK 9.1 & Virtual Hosts nvargas Mandriva 0 09-04-2003 09:25 AM


All times are GMT -5. The time now is 01:14 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration