This howto guide will show you how to purge the varnish cache for a specific URL using the curl command line tool.
This assumes that you have configured the Varnish configuration correctly, to both handle purging, and allowing to purge from your IP address (assuming its locked down to only allow specific IP’s to purge the cache).
Purge the cache with curl:
$ curl -X PURGE http://your_domain/file/to/purge.htm
Example output:
$ curl -X PURGE http://your_domain/file/to/purge.htm <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>200 Purged.</title> </head> <body> <h1>Error 200 Purged.</h1> <p>Purged.</p> <h3>Guru Meditation:</h3> <p>XID: 658321587</p> <hr> <p>Varnish cache server</p> </body> </html>
While it does say “error” in the above output, it has successfully purged this page from the cache. This is just so that the request doesn’t hit the backend server. The status code of 200 means it was successful.
If it was to fail due to IP permission issue it would look something like this:
$ curl -X PURGE http://your_domain/file/to/purge.htm <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>405 Not Allowed</title> </head> <body> <h1>Error 405 Not Allowed</h1> <p>Not Allowed</p> <h3>Guru Meditation:</h3> <p>XID: 658321587</p> <hr> <p>Varnish cache server</p> </body> </html>