Nginx / memcached configuration problem

I hope you will forgive my asking for help on what I assume is a fairly
obvious error of some sort – but it’s one I’m afraid I can’t figure

Basically, we have a cherrypy back end server that will resolve layer
to IP address, handling requests of the form:




The back end server sets a memcache key/value pair so that the next time
around, nginx can avoid the “@cache_miss” proxy pass the next time

For the most part, all works well – if I request the name of a key in
memcached, (“terrain”, for example) – it gets returned. Likewise, if I
request a key NOT in memcached, the request gets sent to my server.

However, any layers with a name starting with “es_” will always go to
same host – so no need to clutter memcached with lots of keys – I’d
to just convert the key so that it is identical for all such requests…

When I attempt to do so using the code fragment below, however, I get
what I
believe is unusual behavior – requests for anything starting with “es_”
return nothing – no HTTP headers, no data – the socket just closes.

Any thoughts on why?



The nginx configuration file:

server {
listen 80;

    access_log  /data/log/nginx/access.log;
    error_log  /data/log/nginx/error.log;

    location ^~ /static/ {
            root   /data/www;

    location /resolve {
            default_type  text/html;

            set $memcached_key "api:/resolve?$args";
            if ($args ~ "layer=es_") {
                    set $memcached_key "api:/resolve?layer=es_";
            memcached_pass localhost:11211;
            error_page 404 = /;

    # proxy everything else to cherrypy on same computer, port 9000
    location / {


The CherryPy function:

def resolve(self,layer):

    if layer == 'iphone':
        host = """api:/resolve?layer=iphone", 

return host # iphone imagery - go to
load balancer first
elif layer == ‘terrain’:
host = “”“api:/resolve?layer=terrain”,
return host # terrain is on a random nginx
imagery server
elif layer.startswith(‘es_’):
host = “”“api:/resolve?layer=es_”, host)
return host # All earthscape layers will
be on
return ‘not valid’ = True

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs