1

nginx doesn't allow to directly execute external programs, so to run CGIs you need to run an standalone fcgi backend and connect to it with the fastcgi_pass directive.

For php it's easy, e.g. using spawn-fcgi and php5-cgi, but I haven't found anything similar for python.

I know that there are fcgi implementations for specific applications and frameworks, but, is there anything to run plain python CGIs (CGIs implemented with the generic cgi module)?

2 Answers 2

1

Try http://projects.unbit.it/uwsgi/ ?

4
  • 1
    The standard uWSGI operational mode is not good for CGI apps, the best setup would be this one projects.unbit.it/uwsgi/wiki/CGI. In the source distribution there is a python cgi accelerator too
    – roberto
    Dec 24, 2011 at 10:27
  • I have tried this, running uwsgi with /usr/local/bin/uwsgi -c --plugins cgi --socket 127.0.0.1:9001 --cgi /var/www/default/ --pidfile /var/run/fastcgi-python.pid -d /var/log/uwsgi.log and in the nginx config: include uwsgi_params, uwsgi_pass 127.0.0.1:9001 and uwsgi_modifier1 9, and several combinations of all them, and I only get 502 errors and in the logs: unavailable modifier requested: 1. Ideas? Dec 26, 2011 at 17:03
  • uwsgi version needs to be 1.0, now it works with the standalone server, but I have the same error with nginx. Dec 26, 2011 at 18:14
  • It's working now, with uwsgi 1.0, I don't really know why it wasn't working before :\ Dec 26, 2011 at 18:30
0

There's a package known as flup, actually suggested by the official Python documentation. Basically, flup allows you to wrap any application (in your case, a CGI script) in a WSGI server. This may require some tweaking, but it should get you what you're looking for.

There are also some great entries on the nginx documentation covering this issue.

Also note, the act of simply running the Python scripts (via mod_cgi or mod_cgid) is distinctly NOT using FCGI, so without a wrapper around your script, it won't be possible.

I hope this helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .