Module vars set inside if's are not set

Igor Sysoev igor at sysoev.ru
Tue Nov 24 23:58:04 MSK 2009


On Mon, Nov 23, 2009 at 09:38:17PM -0700, Mark Maunder wrote:

> Variables that are used by modules and are set inside 'if' blocks in the 
> nginx.conf file are not being set correctly. My nginx version (-V 
> output) is:
> 
> nginx version: nginx/0.7.64
> built by gcc 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
> TLS SNI support enabled
> configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module 
> --add-module=../nginx_http_push_module-0.69 
> --add-module=../agentzh-echo-nginx-module-b8a0849
> 
> 
> I'm setting $push_channel_id for the nginx_http_push_module using the 
> following if statement.
> 
> location ^~ /fjsub/ {
> 
>      push_subscriber long-poll;
>      if ($arg_id) {
>              set $push_channel_id $arg_id;
>      }
> 
> }
> 
> The variable is set fine outside an 'if' statement but when the if 
> evaluates to true, the variable is not set.
> 
> I have duplicated this behaviour with the echo module as follows:
> 
> This will print "No":
> 
> location ^~ /echo/ {
>          set $myText "No";
>          if ($remote_addr ~* '000'){
>                  set $myText "Yes";
>          }
>          echo $myText;
> }
> 
> 
> But when I replace '000' with '64' which matches my IP address, nginx 
> returns a 404 because the value of $myText is empty which means the echo 
> command didn't have any effect.
> 
> I have duplicated this behavior with only the echo module compiled in 
> and ssl and push removed.
> 
> I've already filed this as a bug on GIT for the NHPM (push) module but I 
> suspect this may be an nginx bug since it is broken across modules.
> 
> This bug also exists on the latest development build:
> 
> nginx version: nginx/0.8.28
> built by gcc 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
> configure arguments: --prefix=/usr/local/nginx 
> --add-module=../agentzh-echo-nginx-module-b8a0849
> 
> What is surprising/confusing is that I'm setting variables inside 
> conditional statements that are used by proxy_pass and that works fine. 
> So does the upstream module (proxy_pass module) handle it's variables 
> differently to the echo and push modules?

The "if" block is ugly hack inside nginx. This is the cause.


-- 
Igor Sysoev
http://sysoev.ru/en/




More information about the nginx mailing list