2

I am running a web-service on Nginx/FastCGI/Django. Our processing time is fairly long and CPU intensive and I would like to be able to run multiple processes of Django/FastCGI to share the load. How do I set Nginx to rout requests from a single source to multiple instances of Django/FastCGI? (I can run the multiple instances on multiple ports/sockets, but I don't know how to make Nginx share the processing load between them.)

Any help much appreciated.

Barry
  • 31
  • 4

3 Answers3

1

http://wiki.nginx.org/NginxHttpUpstreamModule

Works with both proxy_pass and fastcgi_pass.

Martin Fjordvald
  • 7,749
  • 1
  • 30
  • 35
1

I realize the question is for fastcgi, but the easiest and speediest way to spawn and load balance a cluster of Python web applications with nginx is to NOT use fastcgi module, but to use the "uWSGI" module. Example nginx config:

upstream uwsgicluster {
     server 127.0.0.1:9001;
     server 192.168.100.101:9001;
     server 192.168.100.102:9001;
     server 192.168.100.103:9001;
     server 192.168.100.104:9001;
}

server {
    listen   80;
    server_name www.mysite.com mysite.com;
    access_log /srv/www/mysite.com/logs/access.log;
    error_log /srv/www/msysite.com/logs/error.log;

    location / {
        include        uwsgi_params;
        uwsgi_pass     uwsgicluster;
    }

    location /static {
        root   /srv/www/mysite.com/public_html/static/;
        index  index.html index.htm;
    }
}

uWSGI website is here projects.unbit.it/uwsgi/ and be sure to look at the Examples page including Django here: http://projects.unbit.it/uwsgi/wiki/Example

metamemetics
  • 111
  • 1
0

According to the official website, you can spawn the fcgi with the parameter :

cd {project_location}

python ./manage.py runfcgi --settings={project}.settings_production maxchildren=10 \

maxspare=5 minspare=2 method=prefork socket={project_location}/log/django.sock pidfile={project_location}/log/django.pid

Or maybe in the same way as the php-fcgi works in its conf script, where I have (in /etc/init.d/php-fcgi) :

PHP_FCGI_CHILDREN=5

Studer
  • 1,350
  • 9
  • 16