PylonsHQ.

Layout: Fixed-width

Pylons with Lighttpd error handler

Skip to end of metadata
Go to start of metadata
Unknown macro: {metadata-list}
Name Pylons with Lighttpd error handler
Space Pylons Cookbook
Section Deployment
Page Running Pylons with SCGI and Lighttpd
Version 1.0
Status Draft
Reviewed False
Author(s) Paul Shirren
This should be considered a work in progress, feel free to add/extend as necessary.

Introduction

This tutorial describes using lighttpd to serve all files in its document root. Control is passed to Pylons when lighttpd cannot find a file to serve.

This is done using the lighttpd error404 handler. Unfortunately the handler does not set PATH_INFO or QUERY_STRING. To allow Route to work these are set by a wsgi middleware wrapper.

Getting started

Before proceeding lighttpd and pylons should be setup following Running Pylons with SCGI and Lighttpd

Setting up Pylons

Once pylons is serving up pages via lighttpd and scgi we add the middleware.

In config/middleware.py add the following before def make_app:

class Lighty404Fix:
    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
         if 'REQUEST_URI' in environ:
            query = environ['REQUEST_URI'].split('?',1)
            environ['PATH_INFO']=query[0]
            if len(query)==2:
                environ['QUERY_STRING']=query[1]
        return self.app(environ, start_response)

and add the following at the bottom just before return app:

app = Lighty404Fix(app)

Setting up Lighttpd

Next configure lighttpd to use an error handler for 404 pages.

...
server.error-handler-404 = "/main.scgi"
...
scgi.server = ("main.scgi" =>
((
"host" => "127.0.0.1",
"port" => 6500,
"check-local" => "disable")
))
...

Wrapping up

Restart the paste server and lighttpd for the changes to take effect.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Powered by Pylons - Contact Administrators