Latest Version: 0.9.6.2
  Dashboard > Pylons Official Docs > Home > Running Pylons apps with Webservers
  Pylons Official Docs Log In | Sign Up   View a printable version of the current page.  
  Running Pylons apps with Webservers
Added by Philip Jenvey, last edited by Philip Jenvey on Aug 04, 2007  (view change) show comment
Labels: 
(None)

This document assumes that you have already installed a Pylons web application, and created a configuration for it. Pylons applications use PasteDeploy to start up your Pylons WSGI application, and can use the flup package to provide a Fast-CGI, SCGI, or AJP connection to it.

Using Fast-CGI

Fast-CGI is a gateway to connect web severs like Apache and lighttpd to a CGI-style application. Out of the box, Pylons applications can run with Fast-CGI in either a threaded or forking mode. (Threaded is the recommended choice)

Setting a Pylons application to use Fast-CGI is very easy, and merely requires you to change the config line like so:

1
2
3
4
5
6
7
8
9
# default
[server:main]
use = egg:Paste#http

# Use Fastcgi threaded
[server:main]
use = egg:PasteScript#flup_fcgi_thread
host = 0.0.0.0
port = 6500

Note that you will need to install the flup package, which can be installed via easy_install:

1
$ easy_install -U flup

The options in the config file are passed onto flup. The two common ways to run Fast CGI is either using a socket to listen for requests, or listening on a port/host which allows a webserver to send your requests to web applications on a different machine.

To configure for a socket, your server:main section should look like this:

1
2
3
[server:main]
use = egg:PasteScript#flup_fcgi_thread
socket = /location/to/app.socket

If you want to listen on a host/port, the configuration cited in the first example will do the trick.

Apache Configuration

For this example, we will assume you're using Apache 2, though Apache 1 configuration will be very similar. First, make sure that you have the Apache mod_fastcgi module installed in your Apache.

There will most likely be a section where you declare your FastCGI servers, and whether they're external:

1
2
3
4
<IfModule mod_fastcgi.c>
    FastCgiIpcDir /tmp
    FastCgiExternalServer /some/path/to/app/myapp.fcgi -host some.host.com:6200
</IfModule>

In our example we'll assume you're going to run a Pylons web application listening on a host/port. Changing -host to -socket will let you use a Pylons web application listening on a socket.

The filename you give in the second option does not need to physically exist on the webserver, URIs that Apache resolve to this filename will be handled by the FastCGI application.

The other important line to ensure that your Apache webserver has is to indicate that fcgi scripts should be handled with Fast-CGI:

1
AddHandler fastcgi-script .fcgi

Finally, to configure your website to use the Fast CGI application you will need to indicate the script to be used:

1
2
3
4
5
6
7
8
<VirtualHost *:80>
    ServerAdmin george@monkey.com
    ServerName monkey.com
    ServerAlias www.monkey.com
    DocumentRoot /some/path/to/app

    ScriptAliasMatch ^(/.*)$ /some/path/to/app/myapp.fcgi$1
</VirtualHost>

Other useful directives should be added as needed, for example, the ErrorLog directive, etc. This configuration will result in all requests being sent to your FastCGI application.

Can you provide a section for other webservers as well in the regular documentation?

The two mostly used webservers for fastcgi other than Apache are:

  • lighttpd
  • nginx

I use lighttpd, it show a great performance boost with fastcgi, when I switched from Apache to Lighty - at least with other fastcgi stuff.

But I am missing a good documentation with hints for using it with Pylons apps..

Posted by Markus Majer at Feb 14, 2008 15:39 | Permalink
Posted by Senmiao Liu at Jul 09, 2008 21:38 | Permalink
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