Forum: NGINX Nginx as Proxy to Squid Forward Proxy

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Curtis Spencer (Guest)
on 2008-12-30 05:29
(Received via mailing list)
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
André Cruz (Guest)
on 2008-12-30 12:01
(Received via mailing list)
What is your current config?
Curtis Spencer (Guest)
on 2008-12-31 22:11
(Received via mailing list)
On Tue, Dec 30, 2008 at 1:50 AM, André Cruz 
<removed_email_address@domain.invalid> 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
This topic is locked and can not be replied to.