add variable in module, change value in config

Maxim Dounin mdounin at
Wed Oct 26 16:19:25 UTC 2011


On Wed, Oct 26, 2011 at 11:36:00AM -0400, artemg wrote:

> I want to control behaviour of my module at runtime(body filtering
> phase), depending on different data (reg exp in headers, value of
> different variables...), so I decided to add variable in my module, and
> then set value in nginx config with "set" operation in rewrite module. 
> I am adding variable via ngx_http_add_variable() in pre-config, set
> set_handler, and when I am doing "set $my_variable "0" " in nginx
> config, I get "duplicate variable my_variable" on nginx start up. 
> What I am doing wrong?

Most likely you forgot to use NGX_HTTP_VAR_CHANGEABLE flag in 
ngx_http_add_variable() call.

> May be I need to set variable by set, and In my
> module get index, and then get value of variable?

This may be a better approach.  Or just accept a variable (or a complex 
value) in your module configuration directive.

Maxim Dounin

More information about the nginx mailing list