'Nginx conditional proxy_pass within docker ip addresses

I am trying to write nginx.conf file. I want to distinguish whether IP adress is coming from same container or not. I have nginx in my docker container. And, my nginx's upstream is working with service names of docker-compose file. But, sometimes I might get IP addresses from different server and service name is not working at that point.

I want to have a conditional statement to distinguish IP addresses. If it is coming from environment I want to use IP address; otherwise I want to use service name. But, I do not know where to put it and how to put it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source