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

Hi,

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

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:

      /usr/bin/python /var/www/app/manage.py runfcgi method=threaded

host=server_ip port=1111

My intention is to run nginx as a reverse proxy for caching some
pages
(created through django templates). I set the nginx configuration on
this
way:

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 (however I am not sure if I am 

reaching
both servers). 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.

Any idea?

Thanks in advance!!

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

Module ngx_http_fastcgi_module and things nearby.

}

This way the application works

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

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
failing.

Any idea?

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

Change it back, and it should work again.

f

Francis D. [email protected]