Multihop, but with memcached

In the config below, the request has three branches through which it may
travel:

  • Request is a GET, serve from memcached if the key exists.
  • Request is a GET, memcached returns a 4040, so fallback to the app
    server.
  • Request is a POST, PUT, or DELETE, so go straight to the app server.

My question is, how can I unify the second two branches, so as not to
duplicate all the config directives for that branch?

location / {
if ($request_method = GET) {
set $memcached_key $uri;
memcached_pass 127.0.0.1:11211;
error_page 404 502 = @myapp;
break;
}

app config block

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://myapp_mongrels;
}

location @myapp {

app config block (duplicate)

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://myapp_mongrels;
}

On Thu, May 15, 2008 at 3:24 PM, Adam W. [email protected] wrote:

if ($request_method = GET) {
proxy_pass http://myapp_mongrels;

We use includes, it’s not perfect but it cuts down on a lot of
duplication.