title: Passing a proxy for host before hitting URLs mentioned in Nginx/forward proxy
body: <p>I need to pass a host proxy URL to connect to other URLs mentioned as proxy pass in nginx.</p>
  
  <p>Example: If I have to connect to google.com through a Linux server box, I have to set proxy as xyz.org:80 and only then I can connect to google.com.</p>
  
  <p>So how can I achieve it in nginx config?</p>
  
  <p>My Nginx config file sample goes like this:</p>
  
  <pre><code>    server{
         listen     80;
         server_name   *;
        return 301     https://$host$request_uri;
      }
      location / {
        sendfile            on;
        try_files           $uri $uri/ /index.html
                            /keepalive.html;
      }
      location /xyz{
         proxy_pass     google.com/
      }
  </code></pre>
  
  <p>Here, I need to pass my proxy xyz.org:80 in the Nginx config itself and only then I can connect to google.com/.</p>
  
  <p>So basically, every request from my server box should pass via xyz.org:80 to the proxy_pass location mentioned in nginx config.</p>
  
  <p>I tried mapping the http host and served host and passing it in the location but it is not working:</p>
  
  <pre><code>map $http_host $served_host {
          default $http_host;
          xyz.org:80 www.google.com;
      }
  
  location /xyz{
             proxy_pass     google.com/;
           proxy_set_header Host $served_host;
          }
  </code></pre>