Hello!
On Sat, Jun 28, 2014 at 3:18 AM, tziade wrote:
> So I tried to set up the client_max_body_size dynamically using :
>
> set $max_body_size 1M;
> ... some access by lua code runs here...
> client_max_body_size $max_body_size;
>
> Which leads to : "client_max_body_size" directive invalid value..
>
This requires patching the nginx core to add nginx variable support to
the client_max_body_size directive. I could add an patch to the nginx
core bundled by OpenResty for this (at CloudFlare we use such a patch
internally, which has not yet been incorporated into OpenResty yet) if
you really want it. You can also consider requesting this feature in
the nginx mailing list and it's better to be included in the
mainstream nginx.
One (partial) workaround is to test the Content-Length request header
in Lua before reading the request body (either explicitly by
ngx.req.read_body() in Lua or implicitly by ngx_proxy and etc). But
requests using chunked encoding for their request bodies won't work
with this workaround.
>
> How can I do this ? Can I avoid reading the body content in the lua code ?
> or is this mandatory ? is this compatible with using proxy_pass ?
>
If you use the ngx.req.socket() API to read the request body yourself,
then you should use the ngx.req.init_body(), ngx.req.append_body(),
and ngx.req.finish_body() to add the body data you're reading into the
internal nginx data structures for request bodies such that other
nginx modules like ngx_proxy can see it.
Best regards,
-agentzh