Nginx as Proxy to Squid Forward Proxy

Curtis Spencer thorin at gmail.com
Wed Dec 31 22:58:50 MSK 2008


On Tue, Dec 30, 2008 at 1:50 AM, André Cruz <andre.cruz at co.sapo.pt> wrote:
> What is your current config?
>
> André

I have tried a lot variations of a config and put some comments about
what they result in.

  server {
    server_name www.proxytest.to
    listen 80;

    # http://www.proxytest.to/relay_add_http/www.yahoo.com
    # This one causes a redirect to the real http://www.yahoo.com
    location /relay_add_http {
      rewrite      /relay_add_http/([^/]+)  http://$1  break;
      proxy_set_header  X-Real-IP  $remote_addr;
      proxy_redirect false;
      proxy_pass http://squid;
      break;
    }

    # http://www.proxytest.to/relay/http://www.yahoo.com
    # This leads to squid receiving 'http:'  which is invalid
    location /relay {
      rewrite      /relay/([^/]+)  $1  break;
      proxy_set_header  X-Real-IP  $remote_addr;
      proxy_redirect false;
      proxy_pass http://squid;
      break;
    }

    # http://www.proxytest.to/http://www.yahoo.com
    # This one ends up sending 'http:/www.yahoo.com', which is closet
but nginx
    # merges any // it sees into one / according to the documentation
    location / {
      rewrite /(.*) $1 break;
      proxy_set_header  X-Real-IP  $remote_addr;
      proxy_redirect false;
      proxy_pass http://squid;
      break;
    }
  }

This is what happens if you just do it in at the root with no rewrite

   # http://www.proxytest.to/http://www.yahoo.com
   # This results in squid getting '/http://www.yahoo.com', which is invalid
   location / {
      proxy_set_header  X-Real-IP  $remote_addr;
      proxy_redirect false;
      proxy_pass http://squid;
      break;
    }
  }


Any ideas.

Thanks,
Curtis

>
> On Dec 30, 2008, at 3:19 AM, Curtis Spencer wrote:
>
>> Hi,
>>
>> This is kind of a strange request.  What i want to do is get nginx to
>> proxy urls such as the following
>>
>> http://www.mywebsite.com/proxy/www.yahoo.com
>>
>> to a squid forward proxy, essentially grabbing the content of
>> www.yahoo.com from a squid cache.
>>
>> By doing a GET http://www.yahoo.com request, the squid proxy will
>> return back that content.
>> I haven't had any success with getting URL rewriting with the
>> proxy_pass and rewrite module to be able to send that type of GET
>> request to squid.
>> The best I can do is GET /http://www.yahoo.com, which squid calls an
>> invalid request, and therefore does not return the content.
>>
>> Any suggestions how to do this without writing a new nginx module?  I
>> currently am running my own http forward proxy that is more flexible,
>> but I would rather use squid for better scalability and caching.
>>
>> Thanks in advance,
>>
>> Curtis
>>
>> --
>> Curtis Spencer
>> blog.sevenforge.com
>>
>
>
>





More information about the nginx mailing list