Thank you for your replies. I think we have found the root cause. We have found below:
When you are using variables in a proxy_pass directive, nginx will use runtime resolving except if :
the target server is declared as an IP address
the target server name is part of an upstream server group
the target server name has already been resolved (e.g. it matches a server name in another server block)
In our case we have one server block, with default set. Apache is sending server name as legacy.domain.com and nginx also proxying to legacy.domain.com, so I belive because both server name and proxy host is same, nginx not trying to re-resolve the ip address.