PHP-FPM no cache
mdounin at mdounin.ru
Tue Jul 5 13:21:41 MSD 2011
On Tue, Jul 05, 2011 at 02:48:57AM -0400, HTF wrote:
> I added the following directives in my config file
> fastcgi_ignore_headers Expires Cache-Control;
> fastcgi_pass_header Set-Cookie;
You don't need "fastcgi_pass_header Set-Cookie;" in 0.8.54, it's
passed by default.
> - and the caching is working now but I still have few questions:
> 1. "Note though that it's not generally safe as it may cause private
> pages (and/or cookies) to be cached and returned to other clients.
> Handle with care."
> - so should I use the caching in my case if it's working only with the
> 'ignore' option only. Could you tell me when this may happen ("private
> pages and/or cookies to be cached"), could you provide some examples
Consider your backend uses "Cache-Control" for reason, e.g. it
presents personalized pages for each authenticated user. If you
ignore Cache-Control and don't have some user id added to
fastcgi_cache_key - all of your users will see the same cached
That's why recommended aproach is to fix backend to return correct
Cache-Control which allows caching for pages which may be cached
and vice versa.
> 2. Content of my website is not changing often what is the recommended
> validation time - hours, days?
Up to you. This mostly depends on how quickly you need changes to
be shown once they finally happen.
> 3. I have contact form where little message pop after the message is
> submitted. With cache enabled this window appears on a different menu
> tab. How to avoid this, should I exclude contact page from caching or is
> there a better way to do it?
This looks like a result of problems discussed in (1).
> 4. When I run Apache benchmark (ab -c 100 -n 5 http:domain.com/) the
> website is not cached unless I visit it through web browser then AB also
> use cache. Is there any explanation fort this behaviour?
Just a wild guess: your backend returns some visitor tracking
cookie for ab as it doesn't have one, and hence nginx doesn't
cache responses to ab.
More information about the nginx