# Add variable in module, change value in config

**URL:** <https://www.ruby-forum.com/t/add-variable-in-module-change-value-in-config/213216>\
**Category:** NGINX\
**Created:** [October 26, 2011, 5:36pm UTC](https://www.ruby-forum.com/t/add-variable-in-module-change-value-in-config/213216 "2011-10-26T17:36:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [October 26, 2011, 5:36pm UTC](https://www.ruby-forum.com/t/add-variable-in-module-change-value-in-config/213216/1 "2011-10-26T17:36:48Z")

</div>

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? May be I need to set variable by set, and In my  
module get index, and then get value of variable?

Posted at Nginx Forum:

> **[add variable in module, change value in config](https://forum.nginx.org/read.php?2,217375,217375#msg-217375)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![artemg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@artemg](https://www.ruby-forum.com/u/artemg)\
**Post date:** [October 26, 2011, 6:20pm UTC](https://www.ruby-forum.com/t/add-variable-in-module-change-value-in-config/213216/2 "2011-10-26T18:20:10Z")

</div>

Hello!

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 D.

---

<div class="post-metadata">

**Author:** ![artemg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@artemg](https://www.ruby-forum.com/u/artemg)\
**Post date:** [October 28, 2011, 7:16am UTC](https://www.ruby-forum.com/t/add-variable-in-module-change-value-in-config/213216/3 "2011-10-28T07:16:14Z")

</div>

Thanks for the answer, yes, I forgot NGX\_HTTP\_VAR\_CHANGEABLE flag.

Posted at Nginx Forum:

> **[Re: add variable in module, change value in config](https://forum.nginx.org/read.php?2,217375,217453#msg-217453)**
>
> 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...
