This document discusses using Varnish as a reverse proxy and HTTP accelerator. It begins with an overview of reverse proxies and caching, then describes how Varnish handles cache hits and misses. Specific techniques covered include using HTTP headers like Cache-Control and surrogate keys to manage caching and invalidations. The document also shows how to configure Varnish using Varnish Configuration Language (VCL) and integrate it with Rails applications and services like image processing.
5. Reverse proxy
In computer networks, a reverse proxy is a type of
proxy server that retrieves resources on behalf of a
client from one or more servers.
6. Request / Response Cycle
Client
Reverse
Proxy
Origin Server
www.hward.com
hward.herokuapp.com
(CNAME)
(or IP Address)
20. Edge-Cache Headers
Only cache publicly accessible pages.
Cache-Control Header:
public, max-age or s-maxage > 0, and remove
any cookies from the response.
$ curl -v http://www.example.com -o /dev/null
< HTTP/1.1 200 OK
< Cache-Control: max-age=30, public
28. 1000 Requests / Minute
Cache TTL
Hit Ratio
Origin Requests / Minute
5 sec
98.00%
20
30 sec
99.80%
2
1 min
99.90%
1
5 min
99.997%
<1
29. 50,000
1000 Requests / Minute
Cache TTL
Hit Ratio
Origin Requests / Minute
5 sec
99.96%
20
30 sec
99.996%
2
1 min
99.998%
1
5 min
99.999%
<1
30. PURGE Requests
Invalidate cache with PURGE request to URL.
$ curl -v -X PURGE http://www.hward.com
> PURGE / HTTP/1.1
< HTTP/1.1 200 OK
< Status: 200 OK
< Via: 1.1 varnish
{"status": "ok", "id": "68-1392243590-232248"}
Note: In Production make sure to whitelist IP’s that can Purge.