LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Sub Domains & Virtual Hosts (https://www.linuxquestions.org/questions/linux-general-1/sub-domains-and-virtual-hosts-241853/)

oO_SwooP_Oo 10-12-2004 03:56 PM

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.

oO_SwooP_Oo 10-12-2004 08:56 PM

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?

viniosity 10-12-2004 10:32 PM

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.

oO_SwooP_Oo 10-13-2004 06:36 PM

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?

oO_SwooP_Oo 10-13-2004 07:42 PM

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.

oO_SwooP_Oo 10-14-2004 02:38 AM

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?

viniosity 10-14-2004 09:53 AM

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

oO_SwooP_Oo 10-14-2004 02:25 PM

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

viniosity 10-14-2004 03:00 PM

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. :o(

oO_SwooP_Oo 10-14-2004 04:29 PM

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

oO_SwooP_Oo 10-15-2004 12:26 PM

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 :)

lemynshij 09-21-2005 02:07 PM

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?


All times are GMT -5. The time now is 07:04 AM.