Marcus Clyne ngx.eugaia at
Wed Dec 23 13:17:56 MSK 2009


agentzh wrote:
> On Wed, Dec 23, 2009 at 8:36 AM, dylanz <nginx-forum at> wrote:
>> location /first {
>>  echo "before";
>>  echo_location_aysnc /second$request_uri;
>>  echo "after"
>> }
>> location /second(.*)\?(.*)^ {
>>  set $memcached_key $1;  # needing this to be keyed on the request_path, not the entire uri
>>  memcached_pass;
>> }
Two problems here :

1) The location directive doesn't test query strings, it tests just the 
URL (before the ?), so this will always fail unless you've URL-encoded 
the '?' character - you should use

if ($arg_[name] ~ [REGEX PATTERN]) {
    # do something

if you want to test an argument

2) The '^' should be a '$' if you wanted it to mean the end of the 
string - I think here it would be testing a literal '^' character

As an extra note, if you're planning on doing such subqueries, you're 
probably better off not using regexes on the subquery location - it's a 
waste of resources.

Do something like

location   /first {
    echo_location_async   /sub/$request_uri;

location   ^~    /sub {
    internal;    # see below

    set   $memcached_key ...

The ^~ is the most efficient way of testing a static location (rather 
than just location /sub or using regexes).
Specifying the location as 'internal' will prevent direct access to the 
url from a request (it's ok for internal subrequests or redirects, 
though).  You may or may not want to do this.

If you can avoid doing rewrites to get the $memcached_key, it would be 
better - no wasting resources.


More information about the nginx mailing list