John,
I’m guessing that you have the if… configuration inside a ‘server if’
rather than a ‘location if’ block. In the latest version (0.7.43),
memcached pass can only be set in ‘location’ and ‘location if’, so you
can’t set it in ‘server if’ blocks.
You have (at least) two options;
- Put your if statement inside a location block
e.g.
location / {
if ($http_cookie != “session_id=”) {
set $memcached_key $uri;
memcached_pass 127.0.0.1 11211;
default_type text/html;
}
}
Note : this could get tedious if you have multiple locations, so you
might want to put the check in a separate file, and just include it -
i.e.
<session_check.conf>
if ($http_cookie != “session_id=”) {
set $memcached_key $uri;
memcached_pass 127.0.0.1 11211;
default_type text/html;
}
<nginx.conf>
…
location / {
include session_check.conf;
}
- Modify the source code of the memcache module (this is easy)
change line 60
- NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
This will allow you to set memcache_pass in any block (except other
upstream ones). All the macros apart from the last one refer to where
the directive is allowed, the meanings of which should be pretty clear
if you are familiar with config files. The key one for you to add is
the NGX_HTTP_SIF_CONF one, which will allow the directive to be included
in if statements at the server level.
If you want to use other memcache directives in other blocks than
location/location-if ones, then you’ll need to bit-or any other blocks
you want to set them in. You could copy all the entries on the above
line except for NGX_CONF_TAKE1 (which refers to the number of arguments
allowed in the config, and you shouldn’t change that for the other
directives).
Note : I’ve not tried this, and there may be a reason why you can’t use
the memcache_pass directive in other blocks (but if there is, I don’t
know it). If there’s no reason for not including it at the server/main
level as well (it’s sometimes convenient to put things there), perhaps
Igor will change the modules to allow that.
One note : the fastcgi_pass directive has the same restrictions as
memcache_pass. It probably works because you’ve put it in a location or
location-if, and it’s not at the server / main level.
Cheers,
Marcus.