Select upstream by subdomain

adamjt nginx-forum at nginx.us
Mon Jul 18 18:42:50 UTC 2011


We are rewriting our app and would like to migrate accounts to the new
back end in chunks, though not in alphabetical sequence. All accounts
have unique subdomains. We have thousands of accounts so I don't think
that putting the rewrite rules in manually would be feasible. I thought
that maybe a key-value store would be a good solution, so I built nginx
with the memc-nginx-module. Now I'm getting stuck.

Here's what I would like to happen: when a request comes in, ngnix uses
the subdomain as the key and checks for its existence in memcached. If
so, it gets passed to the new back end. If not, it goes to the old back
end.

Here's what I have so far:

upstream memback {
    server 127.0.0.1:11211;
    keepalive 1024 single;
}

location @old {
    proxy_pass localhost:7001;
}

location @new {
    proxy_pass other_host:7001;
}

location / {
    set $memc_key $arg_key;
    memc_pass memback;
}

I can't figure out how to capture the response (404 or 200) from
memcached and route the request to the proper back end. Am I going about
this totally wrong? Thanks!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,212573,212573#msg-212573




More information about the nginx mailing list