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
to
which quite easy, problem begins when want allow query string should go path of url so:
from
to
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
Post a Comment