3

How can I configure nginx to pass a PURGE request from localhost to the Varnish backend?

Currently, the script causes this line to appear in the nginx logs:

127.0.0.1 - - [23/Apr/2012:20:12:31 -0500] "PURGE /blog HTTP/1.1" 405 173 "-" "-"

Is there any way to rewrite this purge request to the Varnish backend (127.0.0.1:8080)?

Mahmoud Al-Qudsi
  • 559
  • 1
  • 6
  • 23

1 Answers1

3

Something like this could work:

error_page 418 = @purgepass;

location / {
    if ($request_method = PURGE ) {
        return 418;
    }
}

location @purgepass {
    proxy_pass http://localhost:8080;
}

Not tested, but in theory it should work.

Based on http://blog.rogeriopvl.com/archives/nginx-and-the-http-options-method/

Sašo
  • 1,494
  • 2
  • 10
  • 14