Edgewall Software
Modify

Opened 9 years ago

Closed 6 years ago

Last modified 6 years ago

#12479 closed enhancement (wontfix)

Allow tracd to select environment with Host header

Reported by: rob.nikander@… Owned by:
Priority: normal Milestone:
Component: web frontend/tracd Version: 1.0.11
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

It would be nice to run one instance of tracd, for multiple projects, and have it serve them from URLs that differ only in hostname, like:

  • http://apples.domain.com/
  • http://bananas.domain.com/

Attachments (0)

Change History (4)

comment:1 by Jun Omae, 9 years ago

You could use custom trac.wsgi script with an wsgi container (e.g. mod_wsgi) like this:

#! /usr/bin/python
# -*- coding: utf-8 -*-

import os
import re

from trac.web.main import dispatch_request


_envs_dir = '/path/to/trac'

_host_re = re.compile(r'([A-Za-z._-]+)(?::[0-9]+)?\Z')


def _get_env_path(environ):
    host = environ.get('HTTP_HOST')
    if not host:
        return None
    match = _host_re.match(host)
    if not match:
        return None
    host = match.group(1).rstrip('.').lower()
    if not host:
        return None
    env_path = os.path.join(_envs_dir, host)
    if not os.path.isdir(env_path):
        return None
    return env_path


def application(environ, start_request):
    if 'PYTHON_EGG_CACHE' in environ:
        os.environ['PYTHON_EGG_CACHE'] = environ['PYTHON_EGG_CACHE']

    env_path = _get_env_path(environ)
    if env_path:
        environ['trac.env_path'] = env_path
        return dispatch_request(environ, start_request)
    else:
        status = '404 Not Found'
        output = 'Not Found'
        headers = [('Content-Type', 'text/plain'),
                   ('Content-Length', str(len(output)))]
        start_request(status, headers)
        return [output]

Also, I recommend to use an wsgi container rather than tracd.

Last edited 6 years ago by Jun Omae (previous) (diff)

comment:2 by rob.nikander@…, 9 years ago

I'm using nginx for a webserver, and the TracNginxRecipe recommends I use tracd. No mention on that page of wsgi and I'm guessing that's only for Apache. ?

comment:3 by Jun Omae, 9 years ago

You can use pypi:uWSGI with nginx.

comment:4 by Ryan J Ollos, 6 years ago

Resolution: wontfix
Status: newclosed

If the custom trac.wsgi script (comment:1) is generally useful, it could be a good addition to the CookBook.

Last edited 6 years ago by Ryan J Ollos (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The ticket will remain with no owner.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from (none) to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.