# Using if statements in a location block with set

**URL:** <https://www.ruby-forum.com/t/using-if-statements-in-a-location-block-with-set/246162>\
**Category:** NGINX\
**Created:** [September 7, 2013, 1:43am UTC](https://www.ruby-forum.com/t/using-if-statements-in-a-location-block-with-set/246162 "2013-09-07T01:43:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [September 7, 2013, 1:43am UTC](https://www.ruby-forum.com/t/using-if-statements-in-a-location-block-with-set/246162/1 "2013-09-07T01:43:24Z")

</div>

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:

> **[Using if statements in a location block with set](https://forum.nginx.org/read.php?2,242643,242643#msg-242643)**
>
> 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";
