Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've built a django / python application, running on apache with wsgi, and hosted on a single amazon AWS EC2 instance.

It a custom client application, so low traffic, but one part of my application generates reports, which take a requires more horse power, so I'd like to add an incoming web server which looks at my requests and sends them to one of two application servers.

I am guessing it's not exactly load balancing, because I want to treat the requests for generating documents different from other requests. So I envision apache on one machine, and django on another...

But how do people do this?

  • Do I run a wsgi-based django app on the web server that looks at the request and then forwards it to another machine that is running apache with a wsgi-based django app?
  • Or is there some apache mod that forwards on requests from the web server, and then the application run as stand-alone django servers without apache?
  • Or can a load balancer (like amazon's elastic load balancer) be configured to do this?

I've been having trouble finding documentation on this - is there something in particular I could be searching for?

share|improve this question
up vote 0 down vote accepted

Apparently what I am looking for is FastCGI, which has this capability. Found the answer on the Chapter 21: Deploying Django of the django book, where it says:

FastCGI is an efficient way of letting an external application serve pages to a Web server. The Web server delegates the incoming Web requests (via a socket) to FastCGI, which executes the code and passes the response back to the Web server, which, in turn, passes it back to the client’s Web browser.

The documents also explain How to use Django with FastCGI, SCGI, or AJP. Looks like I can modify the request path and route them to different instances fairly easily.

share|improve this answer

FYI: Deprecated since version 1.7: FastCGI support is deprecated and will be removed in Django 1.9.

I do the same sort of routing using nginx and running django with gunicorn.

Nginx just acts as a reverse proxy and can route your requests in a bunch of different ways.

Set define and name your upstream app servers:

upstream main_site { server         localhost:8000;}
upstream reports   { server;}

And then route requests accordingly

location /reports {
    proxy_read_timeout 1900; #because these requests can take a while
    proxy_pass http://reports;
location / {
    proxy_pass http://main_site;

I've actually done this with 2 of the same app instances on the same box, when i was DB bound but the app server had plenty of juice, so that the long-running reports wouldn't hold app-server threads.

Even if you still run your app from within apache/wsgi, nginx offers a lot of lightweight flexibility. Check it out.

share|improve this answer

Your Answer


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.