[mod_python] mod_python on / and authentication on /login (using trac)

Graham Dumpleton graham.dumpleton at gmail.com
Thu Mar 22 17:51:31 EST 2007

On 23/03/07, Axel Thimm <Axel.Thimm at atrpms.net> wrote:
> Here is the config (hostname masked away):
> <VirtualHost XXX.XXX.XXX:80>
>   ServerName XXX.XXX.XXX
>   DocumentRoot /ext/test/empty
>   <Location "/">
>     Order allow,deny
>     Allow from all
>   </Location>

Not sure you really need the above Location section.

>   <Location "/">
>     SetHandler mod_python
>     PythonPath "sys.path+['/opt/TWWfsw/trac010/lib/python242']"
>     PythonHandler trac.web.modpython_frontend
>     PythonOption TracEnv /ext/test/trac
>     PythonOption TracUriRoot /
>   </Location>
>   <Location /login>
>     AuthType Basic
>     AuthName "MyCompany Trac Server"
>     AuthUserFile /ext/test/.htpasswd
>     Require valid-user
>   </Location>
>   ErrorLog \
>     /var/opt/TWWfsw/httpd222/log/XXX.XXX.XXX/error
>   CustomLog \
>     /var/opt/TWWfsw/httpd222/log/XXX.XXX.XXX/access common
> </VirtualHost>

What happens if you merge all three entries into one under '/'. I
realise this means you can't view Trac pages without first logging in,
but want to see if even that works first. If it doesn't it may point
out where the problem lies, for example, auth files not being readable
properly to Apache user etc.

Only other thing I can suggest is you try experimental mod_wsgi. See:


The configuration using that for what you want to do would be:

  WSGIScriptAlias / /ext/test/trac/apache/trac.wsgi

  <Directory /ext/test/trac/apache>
  Order deny,allow
  Allow from all

   <Location /login>
   AuthType Basic
   AuthName "MyCompany Trac Server"
   AuthUserFile /ext/test/.htpasswd
   Require valid-user

Create the directory:


and in it add trac.wsgi containing:

  import os
  os.environ['TRAC_ENV'] = '/ext/test/trac'
  os.environ['PYTHON_EGG_CACHE'] = '/ext/test/trac/mysite/eggs'

  import sys
  path = '/opt/TWWfsw/trac010/lib/python242'
  if not path in sys.path:

  import trac.web.main

  application = trac.web.main.dispatch_request

How it does things is a bit different to how you have do things with
mod_python, but the difference might be enough to get around whatever
strangeness is going on with your Apache configuration. Read the
instructions for mod_wsgi to get a better understanding of how to set
it up.


More information about the Mod_python mailing list