Latest Version: 0.9.6.2
  Dashboard > Pylons Cookbook > ... > Running Pylons with SCGI and Lighttpd > Pylons with Lighttpd error handler
  Pylons Cookbook Log In | Sign Up   View a printable version of the current page.  
  Pylons with Lighttpd error handler
Added by Paul Shirren, last edited by Paul Shirren on Oct 13, 2007  (view change)
Labels: 
(None)

Name Space Section Page Version Status Reviewed Author(s)
Pylons with Lighttpd error handler Pylons Cookbook Deployment Running Pylons with SCGI and Lighttpd 1.0 Draft False 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.

Site running on a free Atlassian Confluence Open Source Project License granted to Pylons. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.3.3 Build:#645 Feb 13, 2007) - Bug/feature request - Contact Administrators
Top