In <34AC0117.34546...@hypermart.net> Brian Atkins <br...@hypermart.net> writes:
>We are running an experimental server on port 8000 to try and
>find a way to map subdomains to our user accounts without using
>vhosts. Normally, all users at Hypermart receive a free subdomain
>in the form of username.hypermart.net that they can use instead
>of the regular
www.hypermart.net/username style URL. We can
>afford to do that since we are using non-IP vhosts, but we have
>over 2500 members now, which has pushed us up close to 3k vhosts
>(we also host full domains like
www.mycompany.com), which in
>turn is causing our httpd processes to be around 6meg in size
>each.
Make sure you have the minimum amount of directives in each
vhost config and be sure you have the minimum number of aliases, etc.
that are not relevant to the vhosts in the main server; they are
inherited by the vhosts. If you have a lot of stuff in the main
server config that isn't relevant to the vhosts, you may be better
off making the main server a vhost and moving that config into
there.
Note that most of the memory is shared on any decent OS; some, however,
do reserve swap for it all which can be a big pain.
Oh yea, we already went through that in PR#1428.
>Since the subdomains make up the vast number of our vhosts, and
>they map perfectly well to our physical dir structure, we are
>trying to simply rewrite all URL requests for subdomains
>internally using mod_rewrite instead of having vhost entries
>for them. Here is our current ruleset:
>RewriteEngine on
>RewriteCond %{HTTP_HOST} ^www\.hypermart\.net:8000$
>RewriteRule ^(.+) - [L]
>RewriteCond %{HTTP_HOST} ^[^.]+\.hypermart\.net:8000$
>RewriteRule ^/icons(.+) - [PT,L]
>RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
>RewriteRule ^([^.]+)\.hypermart\.net:8000(.*) /data1/hypermart.net/$1$2
There are a couple of other problems here.
Most notable, the ServerName means that redirects won't work
properly. For example, try "http://brian5.hypermart.net:8000/stats"
(without a trailing '/') and you will get a redirect to
"http://www.hypermart.net:8000/stats/" because the ServerName isn't
changed.
This relates back to the logging problem in that Apache doesn't know
that it is rewritten based on some header.
I can't think of any way to do this without changing code. What you
could do is change the code to have... no, that won't work...
hmm...
Aha. If you add a line like:
table_set(e, "HOSTNAME", r->hostname);
to add_common_vars in util_script.c, then you can use "%{HOSTNAME}e"
in a custom log directive to get the proper server name. You can
use "%{HTTP_HOST}e" or "%{HOST}i" without any source changes, but
that will only get things in the Host: header; if a request with
a hostname comes in (eg. "GET http://servername/foo/ HTTP/1.0"
instead of
GET /foo/ HTTP/1.0
Host: servername
) it will not be logged properly. The HTTP/1.1 spec says such
requests must not be sent to origin servers but must be accepted,
so it is up to you if you care. Apache won't accept a request in the
prior form without a Host: header anyway, so it would only matter
if the Host: header is different from the one in the URI (in which
case Apache will prefer the one in the URI), but that's a broken client
so probably not worth the worry.
This still, however, doesn't fix the problem with the hostname
sent for redirects. It may be possible to fix that via mod_rewrite, but
I don't overly like that solution.
What I am looking at is changing Apache to use r->hostname in
preference to r->server->server_hostname if r->hostname is set.
The problem is that the place where this is done (construct_url)
doesn't get passed r but only r->server. This would, however, be
fairly easy to hack in but does involve source changes.
This would be a _very_ cool thing to be able to do properly;
especially if you use some domain where you can use wildcard A
records or CNAMES (eg. *.user.example.com); then you don't even
need to add anything to the DNS to make it work. I have played
with it a little bit in the past, but not in depth because I have
no use for it. It certainly does demonstrate a powerful use of
mod_rewrite. I would be very interested to hear of any issues or
problems that come up if you actually implement this.