Nginx specify IP or specify user_agent access question

set $flag 0;
location ~ /my.php.* { 
    if ( $http_user_agent !~* "user agent") {
        set $flag "${flag}1";
    }
    if ( $remote_addr != ip ){
        set $flag "${flag}2";
    }
            
    if ($flag = "012") {
        return 403;  
    }
}

but this has no effect, which god can give us some advice

Jun.10,2022
Menu