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:
/resolve?layer=terrain
or
/resolve?layer=es_layer_23
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?
Thanks,
–Tom
The nginx configuration file:
server {
listen 80;
server_name api.earthscape.com;
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 / {
proxy_pass http://192.168.1.17:9000;
}
}
The CherryPy function:
def resolve(self,layer):
if layer == 'iphone':
host = "208.42.229.173"
cherrypy.thread_data.mc.set("api:/resolve?layer=iphone",
host)
return host # iphone imagery - go to
cacheing
load balancer first
elif layer == ‘terrain’:
host = “208.42.248.164”
cherrypy.thread_data.mc.set(“api:/resolve?layer=terrain”,
host)
return host # terrain is on a random nginx
imagery server
elif layer.startswith(‘es_’):
host = “208.42.229.170”
cherrypy.thread_data.mc.set(“api:/resolve?layer=es_”, host)
return host # All earthscape layers will
be on
info.earthscape.com
else:
return ‘not valid’
resolve.exposed = True