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)?

Jaime Soriano
  • 308
  • 3
  • 15

2 Answers2

1

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

Vadim
  • 1,329
  • 9
  • 8
  • 1
    The standard uWSGI operational mode is not good for CGI apps, the best setup would be this one http://projects.unbit.it/uwsgi/wiki/CGI. In the source distribution there is a python cgi accelerator too – roberto Dec 24 '11 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? – Jaime Soriano Dec 26 '11 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. – Jaime Soriano Dec 26 '11 at 18:14
  • It's working now, with uwsgi 1.0, I don't really know why it wasn't working before :\ – Jaime Soriano Dec 26 '11 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!

Andrew M.
  • 11,182
  • 2
  • 35
  • 29