Configure nginx to use proxy server for all outboud requests

I want to configure nginx in such a way that all requests to destination api url (eg: www.example.com/endpoint) from source server goes through proxy server (http://proxyserverip:proxyserverport)

when i do curl and wget commands to the url (www.example.com/endpoint) it gives me proper response by connecting to proxy server but nginx gives me error like host not found in upstream

i dont want to set anything in /etc/hosts file also as it resolves domain to ip, the destination api url domain should be resolved using proxy server

I’m using redhat server, http_proxy and https_proxy is set in etc/profile also

Read more here: Source link