The instruction given on http://wiki.nginx.org/PythonFlup is to install
nginx supporting python. But I have a working Nginx with php-fpm
supporting PHP. Now I want to add support of python too. Thus, my config
is slightly different. I successfully installed Python 2.6, Django and
python-flup. Everything went good, but python does not work on web (when
visiting test.py, it downloads the file instead of running the script).
How should modify the nginx config to support python?
On Tue, Oct 11, 2011 at 10:11:14AM -0400, etrader wrote:
Hi there,
The instruction given on http://wiki.nginx.org/PythonFlup is to install
nginx supporting python. But I have a working Nginx with php-fpm
supporting PHP. Now I want to add support of python too. Thus, my config
is slightly different.
nginx doesn’t know (or care) that you are using php or python or
anything
else. All it knows is how you have configured different location{}
blocks.
Each request is handled by one location, so you must make sure that you
have the right configuration in the location that your request matches.
How should modify the nginx config to support python?
If you are currently using php-fpm, you probably have something like
location [something that matches urls that should be handled by php] {
fastcgi_pass [your php-fastcgi server];
}
So now that you are adding a separate fastcgi server that is associated
with python, you’ll want to add a new location block like
location [something that matches urls that should be handled by python]
{
fastcgi_pass [your python-fastcgi server];
}
The details depend on what you’re trying to do. The documentation on
“location”, or the debug log, should show you which location is being
used for each request – if it’s not the right one, you’ll need to
adjust the config.
My server is as
server { server_name .domain.com;
listen 80;
root /home/domain.com;
index index.html index.php;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /opt/nginx/conf/fastcgi_params;
}
}
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;
}
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
On Tue, Oct 11, 2011 at 07:09:32PM +0100, Francis D. wrote:
else. All it knows is how you have configured different location{} blocks.
}
used for each request – if it’s not the right one, you’ll need to
adjust the config.
Good luck with it,
BTW, I know that some people prefer to use uWSGI server for python.
On Tue, 2011-10-11 at 20:06 +0100, Keith Fernie wrote:
This is what I’m using with Debian Squeeze & fcgiwrap installed, not just
for python.
fcgiwrap is a completely different beast and doesn’t apply one whit to
running Django. You need to follow the directions you linked to at http://wiki.nginx.org/PythonFlup
Set up a location for your PHP applications
Set up a different location for your Django application and use the
directions from the wiki for getting it configured.
nginx doesn’t know (or care) that you are using php or python or anything
fastcgi_pass [your php-fastcgi server];
“location”, or the debug log, should show you which location is being
used for each request – if it’s not the right one, you’ll need to
adjust the config.
Good luck with it,
BTW, I know that some people prefer to use uWSGI server for python.