How does nginx determine that the variable is empty?

problem description

because the request is to be rewritten, the old version uses an action parameter in body to execute different code. My plan is to use openResty .
to minimize the problem and restore it, using location

location ~ ^/oldpath/interface.php {
    set $target "";
    access_by_lua_file /var/www/script.lua;

    if ($target != "") { -sharp $target
        proxy_pass https://$target;
    }
}

tested that the $targe variable has indeed been set (verified with the echo output), but there is something wrong with the if judgment, which clearly has a value, but does not execute the fragment in if.

Sep.16,2021

then try the following?

  

if ($target ~ *'^ $') {
}

Menu