Welcome! Log In Create A New Profile


Re: HttpProxyModule vs HttpFastcgiModule

Francis Daly
June 20, 2012 02:40PM
On Wed, Jun 20, 2012 at 01:42:23PM -0400, amodpandey wrote:

Hi there,

> 1. As I understand, we have to use HttpFastcgiModule for fastcgi call
> caching and HttpProxyModule for static files.

Not quite.

HttpFastcgiModule is for when you want nginx to talk to a fastcgi server.

HttpProxyModule is for when you want nginx to talk to a http (or https)

They speak different protocols, they use different modules.

(There are other modules for when you want nginx to talk to a server
using yet another protocol.)

The http server you talk to using the proxy module can be as dynamic as
you want -- all nginx cares about is that it communicates using http.

> In most of the
> cases I observed that there are similar directives only varying in the
> prefix, fastcgi_ vs proxy_.

The user-facing parts are deliberately kept broadly similar among all
of the "use a specific protocol to talk to an external server" modules.

> 2. I have a nginx server that has php-fpm.

You have an nginx server; and you have a php-fpm server, which is a
fastcgi server and uses the fastcgi protocol.

Therefore you use the fastcgi module to allow nginx to speak fastcgi to
the fastcgi server.

> There I used the fastcgi_
> cache and I could see the caching. Now I have a proxy server where I
> want to achieve the caching. Now, should I be using fastcgi_ cahe or
> proxy_ cache? Most likely it should be proxy_ cache!! But please help me
> understand.

Now you have a http server, and you want nginx to speak http to it? Use
the proxy module.

fastcgi_cache can be used to cache what is returned from a fastcgi_pass

proxy_cache can be used to cache what is returned from a proxy_pass

> 3. Clould someone also help me understand the flow of fastcgi caching.
> Static caching is somewhat clear.

I'm not sure what you are asking.

"static caching" is based on the http response from a http
server. "fastcgi caching" is based on the fastcgi response from a fastcgi
server, which (deliberately) includes content very similar to that of
a http response.

Which part is unclear?

From the user point of view, you probably don't care about the
difference. Request comes in; response goes out. Maybe the response came
from the cache; maybe the response came from the back-end server. As
the admin, you want to make sure it uses the cache where possible. As
the user, you don't care (unless it is using the cache where it really

> 4. I observed that the fastcgi response is cached as HTTP response (i.e.
> with HEADERS) unlike the static cache (files as sent to the client). I
> hope this is right. Why is this difference as compared to static
> caching.

That doesn't match what I observe with the result of a proxy_cache

> 5. Why is the temp location requied (How is spooling helpful here) ?


If there is a file with the right name in the cache, then it is known
to be correct.

If instead you wrote that file a bit at a time, then a concurrent request
could return a broken partial response.

So write to a temp file, then move to the final place when it is correct.

> 6. fastcgi_cache_use_stale error timeout invalid_header http_500; -
> When is this directive helpful?


Which part is unclear?

All the best,

Francis Daly francis@daoine.org

nginx mailing list
Subject Author Posted

HttpProxyModule vs HttpFastcgiModule

amodpandey June 20, 2012 01:42PM

Re: HttpProxyModule vs HttpFastcgiModule

Francis Daly June 20, 2012 02:40PM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 225
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready