# Condition in location for proxy\_pass

**URL:** <https://www.ruby-forum.com/t/condition-in-location-for-proxy-pass/223754>\
**Category:** NGINX\
**Created:** [October 16, 2012, 6:56pm UTC](https://www.ruby-forum.com/t/condition-in-location-for-proxy-pass/223754 "2012-10-16T18:56:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 16, 2012, 6:56pm UTC](https://www.ruby-forum.com/t/condition-in-location-for-proxy-pass/223754/1 "2012-10-16T18:56:02Z")

</div>

Dear List ,

I need to do a conditional proxy\_pass , but it’s not happening as  
expected  
.

like

set $target  
[http://www.example.com/sso/url.ping?TargetUrl=http://www.example.com/home](http://www.example.com/sso/url.ping?TargetUrl=http://www.example.com/home)

And that $target , I would like to check with $request\_uri in below  
segment  
.

location /sso/ {  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For  
$proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect off;  
----------

```
        ----------
            proxy_pass http://10.20.137.21;
            }

```

---

<div class="post-metadata">

**Author:** ![trm\_asn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7993a0/32.png) [@trm\_asn](https://www.ruby-forum.com/u/trm_asn)\
**Post date:** [October 16, 2012, 7:01pm UTC](https://www.ruby-forum.com/t/condition-in-location-for-proxy-pass/223754/2 "2012-10-16T19:01:18Z")

</div>

Dear List ,

I need to do a conditional proxy\_pass , but it’s not happening as  
expected  
.

like

set $target  
[http://www.example.com/sso/url.ping?TargetUrl=http://www.example.com/home](http://www.example.com/sso/url.ping?TargetUrl=http://www.example.com/home)

And that $target , I would like to check with $request\_uri in below  
segment  
.

location /sso/ {  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For  
$proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect off;  
----------  
if ($target ~ $request\_uri) {  
proxy\_pass [http://10.20.137.21](http://10.20.137.21);  
}  
else {  
return 403;  
}  
------------  
}

Is that possible achieve inside “location” for “proxy\_pass” .

–trm
