Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

http://wiki.nginx.org/NginxHttpUpstreamModule

Works with both proxy_pass and fastcgi_pass.

share|improve this answer

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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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