Question: I've been working on this for a while and can't seem to find any solution.

I have varnish sitting in front of my nginx server, with CloudFlare sitting in front.

When I issue a curl -X PURGE host CloudFlare picks it up and of course denies it with a 503 error. If I use direct.host to bypass CloudFlare it hits the Varnish server and it accepts the request but it does nothing since direct.host isn't used so there is nothing in the cache for that url.

I am using WordPress and there is a WordPress Varnish Purge plugin, it says to add the following line to `wp-config.php`:

```
define('VHP_VARNISH_IP','127.0.0.1')

```

This is specifically to work with proxy servers and/or CloudFlare to make sure the request goes to the Varnish server rather than CloudFlare, but that doesn't seem to help.

Anyone see this before and have any idea?

Answer: 
Your problem is that the purge request is being handled by ClodFlare instead of Varnish.

Keep in mind that:

* In Varnish 3 you should be using `purge;` instead of `set obj.ttl = 0s;`
* Varnish will resolve the object using `vcl_hash`. In Varnish 3 this means, by default [1], that the req.url will be used along with HTTP "Host" header or, if not present, the server IP:

```
sub vcl_hash {
  hash_data(req.url);
  if (req.http.host) {
    hash_data(req.http.host);
  } else {
    hash_data(server.ip);
  }
  return (hash);
}

```
* You can override `vcl_hash` to match your needs

Please take a look at the documentation [2] and Varnish Book info [3] on Bans & Purges

In my opinion you have to options:

1. Issue the purges directly to Varnish circumventing CloudFlare, directly using `curl -H "Host: _host_wich_has_the_url_to_purge" -X PURGE http://_varnish_ip_:_varnish_port/_url_to_purge_`
2. Try to add the CloudFlare IP ranges to your `acl purge` (not recommended) and instruct CloudFlare to pass such requests to Varnish.

[1] <https://www.varnish-cache.org/docs/3.0/reference/vcl.html#examples>

[2] <https://www.varnish-cache.org/docs/3.0/tutorial/purging.html>

[3] <https://www.varnish-software.com/static/book/Cache_invalidation.html#removing-a-single-object>
Cloudflare, when you hand them your DNS, will set up direct.yourdomain.com. You should be able to issue the PURGE directly to that address, which will bypass Cloudflare and hit your Varnish server directly. Make sure any ACL blocks that you have allow the address that you're sending the PURGE from, however.