title: Rewrite nginx host and proxypass to squid
body: <p>I want to achieve the following:</p>
  
  <p>Request Host:</p>
  
  <p><a href="http://example.com.proxy.myserver.com">http://example.com.proxy.myserver.com</a></p>
  
  <p>Should be rewritten to</p>
  
  <p><a href="http://example.com">http://example.com</a></p>
  
  <p>and passed to a squid server via nginx proxypass.</p>
  
  <pre><code>server {
    listen 80;
    server_name ~^(?&lt;subdub&gt;.*)\.proxy\.myserver\.com$;
    location / {
      rewrite ^ $scheme://$subdub break;
      proxy_set_header  X-Real-IP $remote_addr;
      proxy_set_header  Host $scheme://$subdub;
      proxy_set_header  Request-URI $scheme://$subdub;
      proxy_pass http://localhost:3128;
      proxy_redirect off;
    }
  }
  </code></pre>
  
  <p>The problem is, that nginx redirects this request immediately to <a href="http://example.com">http://example.com</a></p>
  
  <p>Any ideas how to get this working?</p>