Module vars set inside if's are not set

Mark Maunder mark at
Tue Nov 24 07:38:17 MSK 2009

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 

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 

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?



Mark Maunder <mark at>

More information about the nginx mailing list