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?

2
  • Does it have to be nginx? Can it be lighttpd?
    – Keith
    Aug 13, 2011 at 3: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. Aug 13, 2011 at 3:46

2 Answers 2

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.

4
  • wiki.nginx.org/NginxSimplePythonFCGI Appears to only focus on Turbogear projects, and likewise, 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, 2011 at 3: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, 2011 at 3: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, 2011 at 3:53
  • 1
    I think things have stabilized. You can also check out the mod_wsgi info in the linked question. I also just saw serverfault.com/questions/16114/nginx-modwsgi-bad which might give more info.
    – agf
    Aug 13, 2011 at 3:57
0

Use fastcgiwrap.

Available in most distros.

apt install fastcgiwrap

For config, see tutorial at https://techexpert.tips/nginx/python-cgi-nginx/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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