Using if statements in a location block with set

Is the following going to work as expected:

location /v1/users {
rewrite ^/users/(.*)/accounts$ /v1/users/$1/accounts
break;

    if ($server_name = 'js.mydomain.com') {
        set $backend  "api.mydomain.com";
    }

    if ($server_name = 'js-s.mydomain.com') {
        set $backend  "api-s.mydomain.com";
    }

    proxy_pass     https://$backend;
}

Posted at Nginx Forum: