title: Reverse proxy from nginx to squid
body: <p>Similar to <a href="https://stackoverflow.com/questions/11029129/can-squid-run-behind-nginx">this</a>, I am trying to host a squid proxy behind nginx:</p>
  
  <p><code>example.com</code> - the main site</p>
  
  <p><code>relay.example.com</code> - the squid server.</p>
  
  <p>So far, when I try to use the squid proxy, it will complain about accessing an illegal page, for example, if I try to access <code>http://www.google.com</code>, I get an Invalid URL error saying that the URL <code>/http://www.google.com</code> (note the preceding /). Could anyone suggest why this is happening, or a fix for nginx or perhaps in the squid config?</p>
  
  <pre><code>upstream @squid {
      server localhost:3128;
  }
  
  server {
      listen 80;
      server_name relay.example.com;
  
      location / {
          proxy_pass http://@squid/$scheme://$host$uri;
  
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Request-URI $request_uri;
  
          proxy_redirect off;
      }
  }
  </code></pre>
  
  <p><a href="https://i.imgur.com/qtgrZI9.png?1" rel="nofollow noreferrer" title="An image of the issue">https://imgur.com/qtgrZI9</a></p>
  
  <p>The log from squid gives:</p>
  
  <pre><code>1423083723.857      0 127.0.0.1 NONE/400 3530 GET /http://www.google.com/ - HIER_NONE/- text/html
  </code></pre>
  
  <p>And nginx for the same request:</p>
  
  <pre><code>12.34.56.78 - - [04/Feb/2015:16:02:03 -0500] "GET http://www.google.com/ HTTP/1.1" 400 3183 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/35.0" "-"
  </code></pre>