15

I am looking to run standalone python scripts through fcgi for use with nginx, but I have no idea where to start with spawning the processes. Currently, I have PHP successfully with nginx+fcgi, but I'm unsure if/how I can do the same with python. Any suggestions on where to start?

acagastya
  • 323
  • 2
  • 14
WilHall
  • 11,644
  • 6
  • 31
  • 53
  • Does it have to be nginx? Can it be lighttpd? – Keith Aug 13 '11 at 03:11
  • 2
    Semi off-topic, but you really might want to look at one of the lightweight WSGI frameworks. Should be the work of an hour or so to port existing code, and performance will be MUCH better. – Tyler Eaves Aug 13 '11 at 03:46

1 Answers1

30

See the python docs section on FCGI. Basically, with Python, you use the WSGI interface on top of an fcgi server which talks to the web server (the fcgi client).

See Python + FastCGI for a couple of Python fcgi servers.

Edit:

This nginx wiki page explains exactly how to set up Python with nginx using fcgi.

This wiki page describes the uWSGI module for nginx, which is the natural way to use Python with a web server, if you don't really need to use fcgi. This blog entry also looks like good info on uWSGI.

In production, Apache + mod_wsgi or Nginx + mod_wsgi? has some useful info for nginx mod_wsgi as well.

Kos
  • 4,890
  • 9
  • 38
  • 42
agf
  • 171,228
  • 44
  • 289
  • 238
  • http://wiki.nginx.org/NginxSimplePythonFCGI Appears to only focus on Turbogear projects, and likewise, http://wiki.nginx.org/PythonFlup appears to handle only Django. With the latter, would I be able to run just single .py files? Because I'm currently using the latter setup for a django app on the same server - but I was under the impression it only worked with django deployments. – WilHall Aug 13 '11 at 03:46
  • 2
    See the link to the docs in my post -- flup is the example used, and it has nothing to do with Django. Also, if you don't need to use fcgi, I added a couple of links to using WSGI directly with nginx through mod_WSGI or uWSGI. – agf Aug 13 '11 at 03:49
  • 1
    I don't have any particular reason to be using fcgi, so using WSGI directly is probably better. However, I read somewhere earlier that uWSGI is "barely stable" with the newest releases of nginx. Old news? – WilHall Aug 13 '11 at 03:53
  • 1
    I think things have stabilized. You can also check out the mod_wsgi info in the linked question. I also just saw http://serverfault.com/questions/16114/nginx-modwsgi-bad which might give more info. – agf Aug 13 '11 at 03:57