title: nginx transparent proxy: how it works?
body: <p>I have a transparent proxy server running on port 8008, I want to send some $uri to this proxy. This is what I have in the proxy server:</p>
  
  <pre><code>server
  {
      listen 8008;
      location / {
          resolver 8.8.8.8;
          proxy_pass http://$http_host$request_uri;
      }
      access_log /var/log/nginx/proxy_access.log;
  }
  </code></pre>
  
  <p>This actually works - if I put my host:8008 in any of my browser setting, <code>proxy_access.log</code> will show records like:</p>
  
  <pre><code>myb.row.ser.ip - - [12/Feb/2014:20:09:24 -0600] "GET http://col.stb01.s-msn.com/i/4B/7CC71C50462D34411C88C3623A69A.jpg HTTP/1.1" 200 9075 "http://www.msn.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
  </code></pre>
  
  <p>Please note the `"GET <a href="http://col.stb01" rel="nofollow">http://col.stb01</a>..." portion.</p>
  
  <p>Under one of my virtual server, I setup for a location (sample uri: <code>/www.patterns.com/cat/subcat/sample.html</code>):</p>
  
  <pre><code>location ~* (patterns)
  {
      set $hostx "";  
      set $addrs "";  
      if ( $uri ~ "^/(.*?)(/.*)$") {  
          set $hostx $1;  # could be www.patterns.com
          set $addrs $2;  # could be /cat/subcat/sample.html
      }
  proxy_pass http://127.0.0.1:8008/http://$hostx$addrs;
      proxy_set_header referer "";
  }
  </code></pre>
  
  <p>The above code does send the captured uri to my proxy server, however what the proxy server sees is different, from the <code>proxy_access.log</code>:</p>
  
  <pre><code>127.0.0.1 - - [12/Feb/2014:20:44:28 -0600] "GET /http://www.patterns.com/cat/subcat/sample.html HTTP/1.0" 502 574 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"
  </code></pre>
  
  <p>Please note the leading slash in: <code>"GET /http://www.patterns.co..."</code>, I believe that causes the proxy server to return the 502 code.</p>
  
  <p>Now my question is: in my location, how do I send the correct uri to the proxy server?</p>
  
  <p>Thanks,</p>