Deploy WSGI application with FastCGI

465 Views Asked by At

I was trying to deploy Plone 5 with WSGI and FastCGI. Based on a link on official Plone 5 document, Plone 5 supports deployment with WSGI. I can successfully run bin/paste serve zope.wsgi based on the link above, and see the Plone 5 home page.

The next step is wrapping the WSGI application with flup, which make it compatible with FastCGI. I created two files:

dispatch_fcgi.py:

#!/usr/bin/env python
ve = '/home/xxx/Plone/zinstance'

import site
site.addsitedir(ve+'/eggs')

from flup.server.fcgi import WSGIServer
from paste.deploy import loadapp

wsgi_app = loadapp('config:'+ve+'/zope.wsgi')

if __name__ == '__main__':
    WSGIServer(wsgi_app).run()

and

dispatch.fcgi:

#!/bin/bash
this_dir=`dirname $0`

export HOME=/home/xxx
source "$HOME/Plone/zinstance/bin/activate"

err_log_file="${this_dir}/../logs/dispatch_err.log"
exec python "${this_dir}/dispatch_fcgi.py" "$@" 2>>"${err_log_file}"

.htaccess redirects all requests to dispatch.fcgi, which set up all environments and pass arguments to dispatch_fcgi.py. The latter one then load the WSGI configuration file with Paste, and run it.

Ideally, it should run exactly the same as running with ./bin/paste serve zope.wsgi. However, it shows me the default Zope page, and I cannot access ZMI because it keeps asking me for password (I can access it with paste serve). Also, the URL is weird, like 'http://xxxxxx/dispatch.fcgi/manage', where dispatch.fcgi should not be a part of it.

Any idea why the behaviour is different when executing ./bin/paste serve zope.wsgi and running paste inside a script?

UPDATE: .htaccess

Options +ExecCGI
AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteRule   ^(dispatch\.fcgi/.*)$  - [QSA,L]
RewriteRule   ^(.*)$  dispatch.fcgi/$1 [QSA,L]
0

There are 0 best solutions below