You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Aaron Todd <to...@gmail.com> on 2008/06/17 02:37:35 UTC

[users@httpd] Subdomain Config Questions

Hello,

I am looking to configure Apache in a way that I've never done  
before.  I've tried describing this to google to see what it spits  
out, but I am unsure of the results.  What I am looking to do is have  
a set of files in the main web root of my server.  I'd like any  
subdomain to use these files as it it would if they were in its own  
web root.  The google searching I did seemed to come back with  
"subdomain wildcards".  I have tried any of the configuration examples  
I found on it yet.  So it may or may not be what I want.  The seconds  
thing I need to happen is that I'd like to set a PHP session variable  
based on the subdomain name.  Or set something to I can distinguish  
between each one given.  Basically I'd like a.domain.com and  
b.domain.com to be structured exactly the same, but serve up different  
content text and images.  When I update the main code it will update  
for all the subdomains without uploading files to each one.

If anyone can let me know if this possible I would really appreciate it.

Thanks,

Aaron

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Subdomain Config Questions

Posted by André Warnier <aw...@ice-sa.com>.
Aaron Todd wrote:
> Everyone,
> 
> Thank you for all your help.  There was some good stuff in there.  But
> ultimately I followed this web site:
> http://allyourtech.com/content/articles/25_11_2005_setting_up_wildcard_subdomains_on_apache.php
> 
> This is giving me what I want, minus the environmental variable.  Now that I
> think about it I should be able to pull out the entered subdomain using PHP
> and will use that to customize the content.
> 
Fine, if that is what you want, who else could complain ?

But I would like to make a comment, so that not everyone would jump on 
this as being the universal panacea.

It will be fine as long as you remember that using that configuration

1a) any access to any hostname ending in .mydomain.com is going to hit 
your (single) virtual server, including some you do not necessarily expect.
For instance, you will gets hits to
a.mydomain.com (which you expect), but also to
whateverinventedname.mydomain.com
123.mydomain.com
etc..
which you might not expect.

1b) if this virtual server is the only one (or just the first one) which 
you define in your httpd.conf, then it will also get hits for instance for
http://123.123.123.123  (assuming this is your IP address)
(meaning someone hitting your site by providing it's IP address, and 
bypassing the DNS entirely).
It will do that, because this virtual server will also be your default 
virtual server, which Apache will default to if it cannot match any
ServerName or ServerAlias directive.
(http://123.123.123.123 would not match a "ServerAlias *.mycompany.com")

1a and 1b may look like the same case superficially, but they are not 
really, and happen for different reasons.

2) the respective domains which you do expect (and the others) will be 
handled by one single virtual server, thus with exactly the same 
configuration.  There is thus no way to have an ever-so-slight 
difference in settings for one subdomain, unless you really do that all 
dynamically.  For instance, if each domain had a different "company 
logo", you would need to choose among them dynamically at runtime.
The same with css stylesheets, authentication rules, etc..
Unless you have a neat tool that does all of that for you automatically, 
this might be a real hassle.

I guess that in the end it depends on how many of those subdomains you 
expect to handle, and how much they would differ from one another.
If you expect a large number, and they are all identical, then a 
solution like this would probably be best.

If on the other hand your sites are just a few, and they share some 
things but not others, then you might want to look at the other 
solution, and just share a DocumentRoot between them, or between some.

There are even ways to "build" a virtual server configuration 
on-the-fly, thus combining the characteristics of both designs above.
And then, there are mod_rewrite and SetEnvIf...

André

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Subdomain Config Questions

Posted by Aaron Todd <to...@gmail.com>.
Everyone,

Thank you for all your help.  There was some good stuff in there.  But
ultimately I followed this web site:
http://allyourtech.com/content/articles/25_11_2005_setting_up_wildcard_subdomains_on_apache.php

This is giving me what I want, minus the environmental variable.  Now that I
think about it I should be able to pull out the entered subdomain using PHP
and will use that to customize the content.

Thanks for all your help.

Aaron

Re: [users@httpd] Subdomain Config Questions

Posted by Krist van Besien <kr...@gmail.com>.
On Tue, Jun 17, 2008 at 02:37, Aaron Todd <to...@gmail.com> wrote:

> If anyone can let me know if this possible I would really appreciate it.

Maybe the easiest would be to use a rewrite:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^/(.*)$  /home/%1/www/$1 [L]

This example comes from here:
http://wiki.apache.org/httpd/RewriteMassVhosting

Krist

-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Subdomain Config Questions

Posted by André Warnier <aw...@ice-sa.com>.

It was thus said that Sean Conner wrote:
> It was thus said that the Great Aaron Todd once stated:
You may prefer to do

> 
> <VirtualHost *:80>
# this will be the default host, when people try to access via
# IP address for instance
>   ServerName	www.example.net
>   DocumentRoot /var/www/somewhere-generic
     SetEnv SITE "wrong address"
> </VirtualHost>
> 
> <VirtualHost *:80>
>   ServerName	a.example.net
>   DocumentRoot /var/www/common
     SetEnv SITE "this is site A"
> </VirtualHost>
> 
> <VirtualHost *:80>
>   ServerName	b.example.net
>   DocumentRoot /var/www/common
     SetEnv SITE "this is site B"
> </VirtualHost>
> 
The first VirtualHost will be used whenever users access your site via 
other than "http://a.example.com" or "http://b.example.com" (e.g. by 
entering "http://120.10.123.123" - this being the IP address of your server)

The following two sites are what you seem to want : use the same 
document directory for both sites (subdomains), but set a variable 
differently depending on which way people come in.
In thisa case, I used SetEnv, which sets an environment value for 
cgi-bin scripts e.g., but with mod_perl you would use PerlSetVar, and 
with PHP something else probably.



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Subdomain Config Questions

Posted by Sean Conner <sp...@conman.org>.
It was thus said that the Great Aaron Todd once stated:
> Hello,
> 
> I am looking to configure Apache in a way that I've never done  
> before.  I've tried describing this to google to see what it spits  
> out, but I am unsure of the results.  What I am looking to do is have  
> a set of files in the main web root of my server.  I'd like any  
> subdomain to use these files as it it would if they were in its own  
> web root.  

  And then ... 

> Basically I'd like a.domain.com and  
> b.domain.com to be structured exactly the same, but serve up different  
> content text and images.  When I update the main code it will update  
> for all the subdomains without uploading files to each one.

  I'm not quite sure exactly what you want, but I'm guessing you want to
house all the content for all the sites under a single folder.  It's
certainly possible to do something like (very minimal configuration here):

<VirtualHost 10.0.0.10:80>
  ServerName	www.example.net
  DocumentRoot	/var/www/html
</VirtualHost>

<VirtualHost 10.0.0.10:80>
  ServerName	a.example.net
  DocumentRoot	/var/www/html/site-a
</VirtualHost>

<VirtualHost 10.0.0.10:80>
  ServerName	b.example.net
  DocumentRoot	/var/www/html/site-b
</VirtualHost>

> The google searching I did seemed to come back with  
> "subdomain wildcards".  I have tried any of the configuration examples  
> I found on it yet.  So it may or may not be what I want.  The seconds  
> thing I need to happen is that I'd like to set a PHP session variable  
> based on the subdomain name.  Or set something to I can distinguish  
> between each one given.  

  Doing things this way, Apache will pass along the domain name of the site
to PHP.  While there is a way to set things up so you can host a vast number
of sites with very little configuration change [1], but the problem with
that is that each host *must* have the same configuration; if you have to
vary the configuration even a bit, then you can't use it (from my
understanding).

  -spc (More on this at [2])

[1]	http://httpd.apache.org/docs/2.0/vhosts/mass.html

[2]	http://httpd.apache.org/docs/2.0/vhosts/


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org