I don't understand how a reverse proxy with caching works.

Let's assume that the cache is empty.

User1 loads index.php (dynamic content). There's no cache, so Nginx queries the php file. The server says "Welcome User1". Nginx stores the webpage using an md5 checksum.

User2 loads index.php. There is a page stored in the cache, so we return this page to the user. It says "Welcome User1", but if we had called the php script, it would have returned "Welcome User2".

How can Nginx know wether or not to call the php script again? My reverse proxy with caching works great, returning dynamic content, but I imagine it's not just "magic".

Is it the php script which returns a header telling Nginx not to cache?

  • This answer may help explain nginx to you. It also mentions gunicorn, which is used to run python code, but maybe there is something like it for php also. serverfault.com/questions/220046/…
    – northben
    Mar 30, 2015 at 14:53

1 Answer 1


Response caching is controlled by the HTTP Cache-Control response header.

If it is set to no-cache or private, then your reverse proxy will not cache the document. Typically private is used for pages sent to logged-in users; it means that proxies must not cache the document, but it's OK for the web browser to do so.

You can see complete details on Cache-Control in RFC 2616 section 14.9 et seq.

  • Is it defined by developpers ? Or does the PHP script automatically detect if it is static content ?
    – mimipc
    Feb 15, 2013 at 8:20
  • 1
    The web application developer adds code to the PHP script to send the appropriate header (if they know what they're doing). Feb 15, 2013 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.