Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running python through fastCGI for nginx

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?

like image 331
WilHall Avatar asked Aug 13 '11 01:08

WilHall


People also ask

Can I run Python on Nginx?

NGINX doesn't “know” how to run Python, so it needs a gateway to an environment that does. FastCGI is a widely used interface for PHP, Python, and other languages. However, a more popular choice for communication between Python and NGINX is the Web Server Gateway Interface (WSGI).

How does Nginx FastCGI work?

FastCGI is a protocol based on the earlier CGI, or common gateway interface, protocol meant to improve performance by not running each request as a separate process. It is used to efficiently interface with a server that processes requests for dynamic content.


1 Answers

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.

like image 67
agf Avatar answered Oct 16 '22 16:10

agf