Use nginx as caching proxy with no conditional get from client

Erik Hermansen asked:

I would like Nginx to be set up as a reverse proxy with caching in front of another web server (origin server). I understand how to do this much.

But what if I don’t want to depend on the web browser to send an HTTP conditional get to take advantage of the caching? Instead, I want Nginx to make an HTTP conditional get to the origin server. If Nginx has stale content, it will update its cache with a new copy from the origin server.

The flow would be like this:

  1. Browser (or other non-browser client) sends HTTP GET request to Nginx. (No conditional get headers).
  2. Nginx sends HTTP GET for requested content to origin server INCLUDING a conditional get header (e.g. “If-Modified-Since”).
  3. If content has been modified, origin server responds with HTTP 200 and content that Nginx uses to update its cache. Otherwise, it responds with HTTP 304 “not modified”, and Nginx does not update its cache.
  4. Nginx responds with HTTP 200 and the requested content to the browser.

The rationale is to reduce the load on the origin server for HTTP requests from the browser that don’t use a conditional get.

My answer:


nginx added this as a new feature in development version 1.5.7.

Add proxy_cache_revalidate on; to your proxy cache configuration, and nginx will revalidate stale content with If-Modified-Since.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.