title: nginx - Forward requests to another proxy
body: <p>So, I have a third party proxy (probably under squid) which will only accept connections from one of my IP's, but I need to be able to access it from a variety of IPs.</p>
  
  <p>So I'm trying to put a nginx to forward requests to this proxy. I know nginx can forward request like this:</p>
  
  <pre><code>location / {
      proxy_pass http://$http_host$uri$is_args$args;
  }
  </code></pre>
  
  <p>This would work if I needed nginx to forward requests directly to the target site, but I need it to pass it to proxy X first. I tried this:</p>
  
  <pre><code>upstream myproxy {
     server X.X.X.X:8080;
  }
  
  location / {
     proxy_pass http://myproxy$uri$is_args$args; // also tried: http://myproxy$http_host$uri$is_args$args
  }
  </code></pre>
  
  <p>But I get "(104) Connection reset by peer". I guess because nginx is proxying like this:</p>
  
  <pre><code>GET /index.html HTTP/1.1
  Host: www.targetdomain.com.br
  </code></pre>
  
  <p>But I need it to proxy like this:</p>
  
  <pre><code>GET http://www.targetdomain.com.br/index.html HTTP/1.1
  </code></pre>