# Nginx counterpart of haproxy's acl dst

**URL:** <https://www.ruby-forum.com/t/nginx-counterpart-of-haproxys-acl-dst/244376>\
**Category:** NGINX\
**Created:** [March 30, 2016, 10:26am UTC](https://www.ruby-forum.com/t/nginx-counterpart-of-haproxys-acl-dst/244376 "2016-03-30T10:26:05Z")\
**Posts on this page:** 3\
**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:** [March 30, 2016, 10:26am UTC](https://www.ruby-forum.com/t/nginx-counterpart-of-haproxys-acl-dst/244376/1 "2016-03-30T10:26:05Z")

</div>

Hi,

does nginx have a variable, that represents the destination IP address  
and  
port, like it was seen/used by the client at the connection time?

Thank you.

WBR,  
Alexey

---

<div class="post-metadata">

**Author:** ![Alexey\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7993a0/32.png) [@Alexey\_S](https://www.ruby-forum.com/u/Alexey_S)\
**Post date:** [March 30, 2016, 12:50pm UTC](https://www.ruby-forum.com/t/nginx-counterpart-of-haproxys-acl-dst/244376/2 "2016-03-30T12:50:57Z")

</div>

Hi.

Am 30-03-2016 10:24, schrieb Alexey S:

> Hi,
> 
> does nginx have a variable, that represents the destination IP address  
> and port, like it was seen/used by the client at the connection time?

Could you mean

> **[$upstream\_addr - Module ngx\_http\_upstream\_module](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#var_upstream_addr)**

Cheers Aleks

---

<div class="post-metadata">

**Author:** ![Alexey\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7993a0/32.png) [@Alexey\_S](https://www.ruby-forum.com/u/Alexey_S)\
**Post date:** [March 31, 2016, 9:00am UTC](https://www.ruby-forum.com/t/nginx-counterpart-of-haproxys-acl-dst/244376/3 "2016-03-31T09:00:10Z")

</div>

Hi Aleks,

I think it’s not the one.  
AFAIU the closest match for HAProxy “dst” is $server\_addr, but it  
doesn’t  
work as good with DNAT, because it hides original destination IP used by  
a  
client, even though there is a way to retrieve this information [1].

My usecase is following:

a) I create iptables rules on the host:  
iptables -t nat -A OUTPUT -p tcp -d 192.168.170.1 --dport 7654 -j  
DNAT --to-destination 127.0.0.1:11123  
iptables -t nat -A OUTPUT -p tcp -d 192.168.170.2 --dport 7654 -j  
DNAT --to-destination 127.0.0.1:11123  
b) Run load balancer on localhost port 11123  
c) Use telnet to hit 192.168.170.1:7654 and 192.168.170.2:7654  
d) I need load balancer to choose different upstreams depending on the  
address I specified on step (c)

It works with HAProxy, but unfortunately I can’t find how to make it  
work  
with NGINX ☹

WBR,  
Alexey.

[1] [haproxy/src/proto\_tcp.c at master · haproxy/haproxy · GitHub](https://github.com/haproxy/haproxy/blob/master/src/proto_tcp.c#L600)
