I'm going to be running multiple subdomains, eventually too many to be able to each have their own config files. I have the vhosts working how I want them so each subdomain has their own folder eg /web/test which will serve webpages for that subdomain. I want to have each subdomain have its own SVN and trac project eg http ://test.mastersiege.com/trac the problem is you cant use variables in apache.
<Location /trac>
SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /var/trac/$1
PythonOption TracUriRoot /trac
</Location>
where $1 = subdomain. and I cant sym link the trac folder into the subdomains home folder and then use vhost_alias's doc root as TracEnv. I tried writing a Perl script in the apache config files which parses the subdomain from the URL much like Using URL within Vhost container with mod_perl dynamically but It didnt work
use Apache2::ServerRec () ;
use Apache2::ServerUtil ();
use Apache2::RequestRec ();
use Apache2::RequestUtil ();
use Apache2::Const qw/OK DECLINED/;
my $s = Apache2::ServerUtil->server;
$s->push_handlers(PerlHeaderParserHandler => sub { my($r) = @_;
if ( $r->hostname =~ m/(.*)\.([^.]+\.\w+)$/ ) {
my($subdomain,$domain) = ($1,$2);
my($TracPath) = "TracEnv /srv/trac/"+$subdomain;
my($TracUri) = "TracUriRoot /testTrac";
$Location{"/testTrac/"} = {
SetHandler => "mod_python",
PythonInterpreter => "main_interpreter",
PythonHandler => "trac.web.modpython_frontend",
PythonOption => $TracPath,
PythonOption => $TracUri
};
if ( $@ ) { warn $@ }
return OK;
} else {
return DECLINED;
}
});
</Perl>
Thats my first ever perl script so Im unsure.. It is possible to use cgi for trac which would solve the problem but it its about 100x slower then mod_python
I would change the mod_python to mod_wsgi. In this configuration you can set TRAC_PATH with an env variable.
Some excerpt from sample static config:
You would have to test and work out how to get subdomain or domain in the RewriteRule to the [E=...].
You can use back-references from pattern when setting the env (like
[E=trac.env_path:%1]
. I'm not sure if you can use other env variables there like[E=trac.env_path:%{HTTP_HOST}]
, documentation does not say anything on this. I guess you should be able to do that. If not, then some more magic with the RewriteRules can maybe help.trac-stable.wsgi for reference:
Later idea - if it is not possible to use
[E=trac.env_path:%{HTTP_HOST}]
then you could pass as much as you need with env variables and construct the env.env_path inside the trac-stable.wsgi.