Nginx as Reverse Proxy Cache of fcgi django app in separate server

Francis Daly francis at
Sat Apr 27 08:58:31 UTC 2013

On Fri, Apr 26, 2013 at 12:40:06PM -0600, Alvaro Mantilla Gimenez wrote:

Hi there,

>    I've been looking on Internet about this but seems all the examples
> available are for a proxy conf or fcgi conf. Not both.

In nginx, each request in handled in one location block. Only the
configuration appropriate to that location block is used. You can use
proxy_pass in one location block, and fastcgi_pass in another.

Perhaps the examples you found didn't want to overcomplicate things?

>    This is my scenario: I have three servers. The first one run only nginx
> (and it should be the entry point for my websites) and the other two
> servers run django apps.
>    Those django apps have been launched as fastcgi applications and listen
> on some ports. For example:

So: your upstream/backend servers speak fastcgi, and do not speak http
or https. In nginx you will want the fastcgi-related directives.

>    My intention is to run nginx as a reverse proxy for caching some pages and things nearby.

>     upstream app {
>     ip_hash;
>     server server_ip1:1111;
>     server server_ip2:1111;
>     }
>     location / {
>         include fastcgi_params;
>         fastcgi_pass app;
>         fastcgi_split_path_info ^()(.*)$;
>     }
>     This way the application works

nginx speaks the fastcgi protocol to the upstream servers, and they

I'm not quite sure what the fastcgi_split_path_info line is doing,
but you say the config works, so that's good.

You have no mention of caching here, which your question said you
wanted. But you can add it, per the documentation.

> (however I am not sure if I am reaching both servers).

What do the logs say?

You can enhance nginx logging; or you can look at the logs for each
upstream server; or you can look at network traffic involving each
upstream server.

Or you can add a different response from each server, so that you can
tell directly which was used.

> But, If I change the configuration to this:
>      location / {
>          proxy_pass http://app;
>    }
>    Then nginx shows an error and I can't see the django app.

If your django app isn't responding to http queries, then asking nginx
to speak http to it isn't going to work.

Possibly the error (either shown, or in the logs) explains what is

>    Any idea?

You have a working configuration. You change it, and have a non-working

Change it back, and it should work again.

Francis Daly        francis at

More information about the nginx mailing list