@@ -178,18 +178,24 @@ Note that if you are using this, you should have a good purging strategy.
178
178
Varnish helper
179
179
==============
180
180
181
+ This helper can be used to talk back to varnish to invalidate cached URLs.
181
182
Configure the location of the varnish reverse proxies (be sure not to forget
182
- any, as each varnish must be purged ) :
183
+ any, as each varnish must be notified separately ) :
183
184
184
185
` ` ` yaml
185
186
# app/config.yml
186
187
liip_cache_control:
187
188
varnish:
188
189
host: http://www.liip.ch
189
- ips: 10.0.0.10, 10.0.0.11 # comma separated list of ips, or an array of ips
190
- port: 80 # port varnish is listening on for incoming web connections
190
+ ips: 10.0.0.10, 10.0.0.11
191
+ port: 80
191
192
` ` `
192
193
194
+ * **host**: This must match the web host clients are using when connecting to varnish.
195
+ You will not notice if this is mistyped, but cache invalidation will never happen.
196
+ * **ips**: List of IP adresses of your varnish servers. Comma separated.
197
+ * **port**: The port varnish is listening on for incoming web connections.
198
+
193
199
To use the varnish cache helper you must inject the
194
200
``liip_cache_control.varnish`` service or fetch it from the service container :
195
201
@@ -223,29 +229,6 @@ Purging
223
229
Add the following code to your Varnish configuration to have it handle PURGE
224
230
requests (make sure to uncomment the appropiate line(s))
225
231
226
- varnish 2.x
227
- ```
228
- #top level:
229
- # who is allowed to purge from cache
230
- # https://www.varnish-cache.org/docs/trunk/users-guide/purging.html
231
- acl purge {
232
- "127.0.0.1"; #localhost for dev purposes
233
- "10.0.11.0"/24; #server closed network
234
- }
235
-
236
- #in sub vcl_recv
237
- # purge if client is in correct ip range
238
- if (req.request == "PURGE") {
239
- if (!client.ip ~ purge) {
240
- error 405 "Not allowed.";
241
- }
242
-
243
- purge("req.url ~ " req.url);
244
- purge("req.url ~ " req.url);
245
- error 200 "Success";
246
- }
247
- ```
248
-
249
232
varnish 3.x
250
233
```
251
234
#top level:
@@ -284,10 +267,34 @@ sub vcl_miss {
284
267
285
268
```
286
269
270
+ In Varnish 2, the `purge` action is actually just marking caches as invalid.
271
+ This is called `ban` in Varnish 3.
272
+
273
+ Varnish 2.x
274
+ ```
275
+ #top level:
276
+ # who is allowed to purge from cache
277
+ # https://www.varnish-cache.org/docs/trunk/users-guide/purging.html
278
+ acl purge {
279
+ "127.0.0.1"; #localhost for dev purposes
280
+ "10.0.11.0"/24; #server closed network
281
+ }
282
+
283
+ #in sub vcl_recv
284
+ # purge if client is in correct ip range
285
+ if (req.request == "PURGE") {
286
+ if (!client.ip ~ purge) {
287
+ error 405 "Not allowed.";
288
+ }
289
+
290
+ purge("req.url ~ " req.url);
291
+ purge("req.url ~ " req.url);
292
+ error 200 "Success";
293
+ }
294
+ ```
287
295
288
296
NOTE: this code invalidates the url for all domains. If your varnish serves
289
297
multiple domains, you should improve this configuration.
290
- Pull requests welcome :-)
291
298
292
299
The varnish path invalidation is about equivalent to doing this:
293
300
@@ -300,7 +307,9 @@ The varnish path invalidation is about equivalent to doing this:
300
307
Banning
301
308
-------
302
309
303
- Since varnish 3 banning can be used to invalidate the cache.
310
+ Since varnish 3 banning can be used to invalidate the cache. Banning
311
+ invalidates whole section with regular expressions, so you will need to be
312
+ careful to not invalidate too much.
304
313
305
314
Configure the varnish reverse proxies to use ban as purge instruction:
306
315
0 commit comments