Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)?

share|improve this question
add comment

1 Answer

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 http://blog.rogeriopvl.com/archives/nginx-and-the-http-options-method/

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: wiki.nginx.org/IfIsEvil#What_to_do_instead –  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
add comment

Your Answer

 
discard

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.