NameVirtualHost doesn't work on subdomains

This is a discussion on NameVirtualHost doesn't work on subdomains within the Linux Web Servers forums, part of the Web Server and Related Forums category; I have namevirtualhost defined but for some reason it's just not working. I'm using wildcards in the form ...


Go Back   Usenet Forums > Web Server and Related Forums > Linux Web Servers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-05-2005
Shabam
 
Posts: n/a
Default NameVirtualHost doesn't work on subdomains

I have namevirtualhost defined but for some reason it's just not working.
I'm using wildcards in the form of XXX.com.site.com and XXX.img.site.com.
It appears only the first virtualhost works. The second one keeps routing
to the document root defined in the first virtualhost
(/www/imgsite/htdocs/com). Wha am I doing wrong here? Does namevirtualhost
not support wildcard subdomains?


NameVirtualHost 1.2.3.4:80

<VirtualHost 1.2.3.4>
ServerName com.site.com
DocumentRoot /www/imgsite/htdocs/com
</VirtualHost>


<VirtualHost 1.2.3.4>
ServerName img.site.com
DocumentRoot /www/imgsite/htdocs
</VirtualHost>



  #2 (permalink)  
Old 04-05-2005
Jorey Bump
 
Posts: n/a
Default Re: NameVirtualHost doesn't work on subdomains

"Shabam" <chalupa@yomama-nospam.com> wrote in
news:hbidndAmjfw-t8_fRVn-rQ@adelphia.com:

> Does namevirtualhost not support wildcard subdomains?


It does with mass virtual hosting feature:

http://httpd.apache.org/docs-2.0/vhosts/mass.html

> NameVirtualHost 1.2.3.4:80
>
> <VirtualHost 1.2.3.4>
> ServerName com.site.com
> DocumentRoot /www/imgsite/htdocs/com
> </VirtualHost>


This will only serve HTTP 1.1 requests for com.site.com, and it will be
the default for any other requests directed to unconfigured hosts on IP
1.2.3.4 because it is the first one listed.

> <VirtualHost 1.2.3.4>
> ServerName img.site.com
> DocumentRoot /www/imgsite/htdocs
> </VirtualHost>


This will only serve HTTP 1.1 requests for img.site.com.

If you don't like mass virtual hosting, you'll need to add a ServerAlias
for every host you expect via your wildcards:

<VirtualHost 1.2.3.4>
ServerName com.site.com
ServerAlias www.com.site.com
ServerAlias foo.com.site.com
DocumentRoot /www/imgsite/htdocs/com
</VirtualHost>

I use mass virtual hosting with mod_vhost_alias, myself. Configuration
looks like this (note the absence of ServerName or ServerAlias):

<VirtualHost *>
ServerAdmin admin@example.net
# turn on mass virtual hosting
# apache will look for DocumentRoot using name of requested host (%0)
VirtualDocumentRoot /var/www/vhosts/%0/site
# make reconstructed self-referential URLs use hostname sent by client
UseCanonicalName Off
</VirtualHost>

Some tips:

Use %V, not %v in your custom LogFormat directive.

LogFormat "%V %h %l %u %t \"%!414r\" %>s %b" vcommon
CustomLog /var/log/apache/vcombined_log vcommon

Open proxy hunters will create unusual entries in your log. When they try
"GET http://www.yahoo.com/ HTTP/1.1", your server will look for
/var/www/vhosts/www.yahoo.com/site/, which, of course, doesn't exist. It
will return a 404 error (no harm done). It will also use www.yahoo.com as
the virtual host in the log entry (if you use the LogFormat above), so
don't freak out when your log analysis program claims you have a virtual
host named www.yahoo.com.


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0