Skip to content

Apache mod_wsgi deployment

Jakob Hirsch edited this page Jul 3, 2017 · 12 revisions

Contributed by Alex Marandon (@amarandon)

To deploy klaus with mod_wsgi, you'll need to create a small Python script exposing a WSGI application. You'll also need to configure Apache so that it uses your script.

You may use the example script shipped with klaus, klaus.contrib.wsgi.

Smart HTTP support

The smarthttp function requires a small change to the apache configuration to properly work. This is due to the fact that mod_wsgi will not send the authentication data to the application to prevent security issues (see wsgi faq). The can be resolved by adding WSGIPassAuthorization On to your virtual host configuration.

See also https://github.com/jonashaag/klaus/issues/102

Then see Smart HTTP for general instructions for enabling Smart HTTP.

Contrib scripts

To use the wsgi_autoreload from contrib, use this wrapper script with the embedded config:

from klaus.contrib.wsgi_autoreloading import make_autoreloading_app

application = make_autoreloading_app(
    "/srv/git/", # root directory of your repositories
    "klaus on BMG LABTECH git server", # site name
# extra options
#    ctags_policy="tags-and-branches",
#    htdigest_file="/path/to",
#    use_smarthttp=False,
#    require_browser_auth=False,
#    disable_push=False,
#    unauthenticated_push=False,
)

Custom script

Here is a custom sample WSGI script:

# -*- coding: UTF-8 -*-
# wsgi.py

# Optional: if you install klaus in a virtualenv, you need to tell Python 
# about your environment's site-packages directory
import site
site.addsitedir('/path/to/env/lib/python2.7/site-packages')


# Your klaus site title. Make sure it's a unicode object if it 
# contains non-ascii characters
TITLE = u"My site title"

# A list of paths pointing to your git repositories
REPOSITORIES = [
    "/path/to/repo1.git",
    "/path/to/repo2.git",
]

# klaus provides a make_app function that creates a WSGI application
from klaus import make_app

# Create the application
application = make_app(REPOSITORIES, TITLE)

And here is a sample Apache virtual host configuration:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName git.example.com

    WSGIScriptAlias / /path/to/wsgi.py  # This should point to your WSGI script
    WSGIDaemonProcess git.example.com user=www-data processes=2 threads=4 display-name=%{GROUP}
    WSGIProcessGroup git.example.com

</VirtualHost>

To enable Smart HTTP, you need to modifiy your WSGI script a little bit:

...
HTDIGEST = open("/path/to/klaus-users")
application = make_app(
        REPOS, TITLE,
        True, HTDIGEST
)
...

If the htdigest parameter is not provided pushing will be disabled.