2

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

1 Answer 1

1

Try this module: https://github.com/chaoslawful/lua-nginx-module

You can modidy args,header, and other magic thing

OpenResty , a better way to use ngx_lua_module : http://openresty.org/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.