nginx / memcached configuration problem

Tom Churchill tom at
Wed Nov 12 08:51:29 MSK 2008

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 out.

Basically, we have a cherrypy back end server that will resolve layer names
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 around.

For the most part, all works well -- if I request the name of a key in the
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 the
same host -- so no need to clutter memcached with lots of keys -- I'd like
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", host)
            return host                   # iphone imagery - go to cacheing
load balancer first
        elif layer == 'terrain':
            host = ""
  "api:/resolve?layer=terrain", host)
            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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list