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:
- Browser (or other non-browser client) sends HTTP GET request to Nginx. (No conditional get headers).
- Nginx sends HTTP GET for requested content to origin server INCLUDING a conditional get header (e.g. “If-Modified-Since”).
- 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.
- 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.
nginx added this as a new feature in development version 1.5.7.
proxy_cache_revalidate on; to your proxy cache configuration, and nginx will revalidate stale content with
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.