Trouble changing uri to query string

i have a url looking as such:
mysite.com/some/path/rest/v2/giveit.view&user=282&imageid=23&size=80

i want the cache key to match imageid=23&size=80 without the “user”
part.

$args isn’t matching because incoming url lacks the “?” part, so $uri is
detected as mysite.com/some/path/rest/v2/giveit.view&imageid=23&size=80

Is there a way i could force nginx to detect that query string, or
rewrite/set the args on each request ?

On Mon, Sep 15, 2014 at 02:57:34PM +0300, Roland RoLaNd wrote:

Hi there,

this is all untested by me…

i have a url looking as such:
mysite.com/some/path/rest/v2/giveit.view&user=282&imageid=23&size=80

i want the cache key to match imageid=23&size=80 without the “user” part.

You could try using “map” to define a variable which is ‘the url without
the part that matches “user=[0-9]+&”’, and then use that in the cache
key, perhaps?

$args isn’t matching because incoming url lacks the “?” part, so $uri is
detected as mysite.com/some/path/rest/v2/giveit.view&imageid=23&size=80

$url probably starts with the character “/”.

Is there a way i could force nginx to detect that query string, or rewrite/set
the args on each request ?

There is no query string.

You may find it easier to switch to “standard” http/cgi-like urls. But
that’s a separate thing.

f

Francis D. [email protected]

Thank you Francis for your response and excuse the late reply.Using map
is cool idea, though i have around 2000 possible imageId and size and
more than 9 million user id… they’re always imageIDs are prone to
change, wouldn’t that mean i have to add them manually every time ?
On another note, let’s say i mapped all wanted cache keys, how can i
force the incoming requests to match with that key ? as i would be stuck
with the same dilemma as now, since the uri as it’s missing the “?”
isn’t treating the arguments as query string but part of the uri
itself…
i am currently researching a way to do the following:
location ~* /some/path/rest/v2/if ^/giveit.view* set $URI
http://mysite.com/some/path/rest/v2/giveit.view?(whatever matched after
view)set $args $args_id$arg_sizeset $cache_key
$scheme$host$uri$is_args$args;
This would only work if the $args reads from the previously set $URI
this is obviously a pseudo code, but i’m hoping i’m on the right path
here…

On Sun, Sep 21, 2014 at 04:40:00PM +0300, Roland RoLaNd wrote:

Hi there,

Using map is cool idea, though i have around 2000 possible imageId and size and
more than 9 million user id… they’re always imageIDs are prone to change,
wouldn’t that mean i have to add them manually every time ?

map can use regex.

However, map can only use a single variable, so I think you would need
two maps (or perhaps a “set” within an “if”) in order to save the
request
uri without the user part.

For example:

map $uri $the_bit_before_user {
~(?P.*)&user=[0-9]+& $m;
default $uri;
}

map $uri $the_bit_after_user {
~&user=[0-9]+(?P&.*) $m;
default “”;
}

followed by a later

set $request_without_user $the_bit_before_user$the_bit_after_user;

could give you a variable that might be useful to use as part of your
cache_key.

On another note, let’s say i mapped all wanted cache keys, how can i force the
incoming requests to match with that key ? as i would be stuck with the same
dilemma as now, since the uri as it’s missing the “?” isn’t treating the arguments
as query string but part of the uri itself…

There are no arguments. There is no query string. There is only the uri
(the location, in this case).

Can you describe what you want to happen when a client makes a request
of nginx?

I imagine it is something like “if nginx has the appropriate response
in cache send it; otherwise do something to populate the cache and send
the response”. But I do not know what you think should populate the
cache in the first place.

f

Francis D. [email protected]