# Use variable instead of flag for modules

**URL:** <https://www.ruby-forum.com/t/use-variable-instead-of-flag-for-modules/183999>\
**Category:** NGINX\
**Created:** [February 23, 2010, 7:15pm UTC](https://www.ruby-forum.com/t/use-variable-instead-of-flag-for-modules/183999 "2010-02-23T19:15:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [February 23, 2010, 7:15pm UTC](https://www.ruby-forum.com/t/use-variable-instead-of-flag-for-modules/183999/1 "2010-02-23T19:15:55Z")

</div>

Hi,

I’m currently developing a filter module, and I want to activate it  
based on  
certain conditions.  
The problem is that the flag is read when the configuration is parsed,  
and  
putting  
my\_module off; inside an if statement has no effect.

I’m now planning on having my module taking variable that can be  
modified  
inside an if statement. But I haven’t been able to find any existing  
module  
that does that.

So I was wondering if the usual way to do this was through rewrites to  
location that have modules enabled or not.  
The problem with that being if you have a lot of conditions then the  
configuration starts being very hard to follow.

Any ideas on how to deal with this ?

---

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [February 23, 2010, 9:51pm UTC](https://www.ruby-forum.com/t/use-variable-instead-of-flag-for-modules/183999/2 "2010-02-23T21:51:42Z")

</div>

Hello!

On Tue, Feb 23, 2010 at 10:15:06AM -0800, Matthieu T. wrote:

> that does that.  
> From developer point of view there is no such thing as “if”  
> statement. There is locations. Using non-rewrite directives  
> inside “if” means they are used in implicit location created by  
> “if”. Note that this produces various weird things as documented  
> here:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

> So I was wondering if the usual way to do this was through rewrites to  
> location that have modules enabled or not.  
> The problem with that being if you have a lot of conditions then the  
> configuration starts being very hard to follow.
> 
> Any ideas on how to deal with this ?

Personally I don’t recommend allowing anything inside “if” due to  
the problems it produce. Either follow “jump to appropriate  
configuration” paradigm (via rewrite or return), or implement  
needed logic in your own module (in case it’s common enough), or  
support variables to control your module.

Maxim D.
