Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Is it defined by developpers ? Or does the PHP script automatically detect if it is static content ? –  mimipc Feb 15 '13 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). –  Michael Hampton Feb 15 '13 at 8:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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