Hi! I'm using nginx to proxy requests from clients to JSON data provider backend. How i can replace one of the request parameters, if one exists, but doesn't satisfies regexp ^\d{1,2}$?
Now i'm at this point:
location / {
if ( $arg_limit !~ "^\d{1,2}$" ) {
rewrite ^(.*)$ $1?limit=10 break;
}
proxy_pass http://data_provider;
}
It works, when limit argument aren't defined, but take place for double limit arguments, if one defined in the request.
Required behaviour:
# no limit arg, add one with default value
/path?key=1 → /path?limit=10&key=1
# arg value satisfies regexp, don't rewrite
/path?key=1&limit=50 → /path?key=1&limit=50
# arg value doesn't satisfies regexp, replace with default
/path?key=1&limit=5000 → /path?limit=10&key=1
Arguments order doesn't matter, of course.
nginx/1.0.10
configure arguments:
--with-ipv6 --with-pcre --with-http_ssl_module
--with-http_addition_module --with-http_xslt_module
--with-http_geoip_module --with-http_gzip_static_module
--with-http_secure_link_module