Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: - - [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 (

share|improve this question
up vote 2 down vote accepted

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

share|improve this answer
IIRC, you can't use proxy_pass in an if statement. – Mahmoud Al-Qudsi Apr 24 '12 at 5:59
Fixed up so proxy_pass isn't directly used inside an if; used method recommended in the manual: – Sašo Apr 24 '12 at 6:15
Interesting approach. I can give it a try tomorrow and let you know :) – Mahmoud Al-Qudsi Apr 24 '12 at 6:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.