Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 1 down vote accepted

Try ?

share|improve this answer
The standard uWSGI operational mode is not good for CGI apps, the best setup would be this one 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 --cgi /var/www/default/ --pidfile /var/run/ -d /var/log/uwsgi.log and in the nginx config: include uwsgi_params, uwsgi_pass 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

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!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.