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

**URL:** <https://www.ruby-forum.com/t/nginx-as-reverse-proxy-cache-of-fcgi-django-app-in-separate-server/228546>\
**Category:** NGINX\
**Created:** [April 26, 2013, 8:41pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-cache-of-fcgi-django-app-in-separate-server/228546 "2013-04-26T20:41:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alvaro\_Mantilla\_Gim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Alvaro\_Mantilla\_Gim](https://www.ruby-forum.com/u/Alvaro_Mantilla_Gim)\
**Post date:** [April 26, 2013, 8:41pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-cache-of-fcgi-django-app-in-separate-server/228546/1 "2013-04-26T20:41:18Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![Alvaro\_Mantilla\_Gim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Alvaro\_Mantilla\_Gim](https://www.ruby-forum.com/u/Alvaro_Mantilla_Gim)\
**Post date:** [April 27, 2013, 10:59am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-cache-of-fcgi-django-app-in-separate-server/228546/2 "2013-04-27T10:59:14Z")

</div>

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](http://nginx.org/r/fastcgi_cache) 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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
