Python on Nginx

Keith Fernie me at keithfernie.co.uk
Tue Oct 11 19:06:32 UTC 2011


This is what I'm using with Debian Squeeze & fcgiwrap installed, not just  
for python.

location ~ (\.cgi|\.py|\.sh|\.pl|\.lua)$ {
     gzip off;
     root  /var/www/$server_name;
     autoindex on;
     fastcgi_pass  unix:/var/run/fcgiwrap.socket;
     include /etc/nginx/fastcgi_params;
     fastcgi_param  DOCUMENT_ROOT      /var/www/$server_name;
     fastcgi_param SCRIPT_FILENAME   
/var/www/$server_name$fastcgi_script_name;
}

Also I chmod +x the python scripts and add
#! /usr/bin/python
to the beginning of the python script.
Change the path if python is located elsewhere.

On Tue, 11 Oct 2011 19:59:50 +0100, Francis Daly <francis at daoine.org>  
wrote:

> On Tue, Oct 11, 2011 at 02:43:32PM -0400, etrader wrote:
>
>> You mean to add another location as
>>     location ~ \.py$ {
>> fastcgi_pass   127.0.0.1:9000;
>> fastcgi_index  index.py;
>> fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
>>     include /opt/nginx/conf/fastcgi_params;
>> }
>
> If all of your python urls end in .py, yes.
>
> Although you probably don't want 127.0.0.1:9000, since that's
> your php-fastcgi server. You'll want whatever your python-fastcgi
> server address is: probably 127.0.0.1:8080, if you followed
> http://wiki.nginx.org/PythonFlup
>
> 	f



More information about the nginx mailing list