nginx - Rewrite query string to path params -


i have following configuration of nginx hosts image service:

    upstream thumbor {         server localhost:8888;     }      server {         listen       80;         server_name  my.imageserver.com;         client_max_body_size 10m;         rewrite_log on;         location ~ /images {              if ($arg_width="10"){                 rewrite ^/images(/.*)$ /unsafe/$1 last;             }             rewrite ^/images(/.*)$ /unsafe/$1 last;         }         location ~ /unsafe {             proxy_set_header x-real-ip $remote_addr;             proxy_set_header host $http_host;             proxy_set_header x-nginx-proxy true;              proxy_pass http://thumbor;             proxy_redirect off;         }          location = /favicon.ico {             return 204;             access_log     off;             log_not_found  off;         }     } 

i trying rewrite following urls:

from

http://my.imageserver.com/images/jenesis/embeddedimage/image/jpeg/jpeg/9f5d124d-068d-43a4-92c0-1c044584c54a.jpeg

to

http://my.imageserver.com/unsafe/jenesis/embeddedimage/image/jpeg/jpeg/9f5d124d-068d-43a4-92c0-1c044584c54a.jpeg

which quite easy, problem begins when want allow query string should go path of url so:

from

http://my.imageserver.com/images/jenesis/embeddedimage/image/jpeg/jpeg/9f5d124d-068d-43a4-92c0-1c044584c54a.jpeg?width=150&height=200&mode=smart

to

http://my.imageserver.com/unsafe/150x200/smart/jenesis/embeddedimage/image/jpeg/jpeg/9f5d124d-068d-43a4-92c0-1c044584c54a.jpeg

also better if order of query strings won't matter.

i tried using: $arg_width didn't seem work.

using nginx 1.6.1 on ubuntu.

help much appreciated.

working query arguments hard (this true apache).

but in example when do:

location ~ /images {      if ($arg_width="10"){         rewrite ^/images(/.*)$ /unsafe/$1 last;     }     rewrite ^/images(/.*)$ /unsafe/$1 last; } 

i not see difference between 2 rewrites... that's maybe why not working.

anyway maybe try (based on this thread):

location ^~ /images {     # there if have query string     if ($is_args) {         set $width "";          set $height "";         if ($args ~* "(?:^|&)width=([^&]+)") {              set $width $1;          }         if ($args ~* "(?:^|&)height=([^&]+)") {              set $height $1;          }          # string concatenation using sort of bash syntax         set $dim "${width}x${height}";         # maybe should add control here on $dim !='x'...          # ? here prevent query string being appended         rewrite ^/images(/.*)$ /unsafe/$dim/$1? last;     }     rewrite ^/images(/.*)$ /unsafe/$1 last; }  location ~ /unsafe {     (...) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -