Odd squid transparent redirect behavior
- by EMiller
This is the first time I've set up squid. It's running a redirect script that does some text search/replace on html pages, and then saves them to a location on the same machine on the nginx path - then issues the redirect to that URL (it's an art project :D).
The relevant lines in squid.conf are
http_port 3128 transparent
redirect_program /etc/squid/jefferson_redirect.py
The jefferson_redirect.py script is based on this script: http://gofedora.com/how-to-write-custom-redirector-rewritor-plugin-squid-python/
The issue:
I'm getting strange http redirect behavior. For example, here is the normal request/response from a PHP script that issues a header("Location:"); - a 302 redirect:
http://redirector.mysite.com/?unicmd=g+yreka
GET /?unicmd=g+yreka HTTP/1.1
Host: redirector.mysite.com
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.5.9-1.fc12 Firefox/3.5.9
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.1 302 Found
Date: Tue, 13 Apr 2010 05:15:43 GMT
Server: Apache
X-Powered-By: PHP/5.2.11
Location: http://www.google.com/search?q=yreka
Content-Type: text/html
Vary: User-Agent,Accept-Encoding
Content-Encoding: gzip
Content-Length: 2108
Keep-Alive: timeout=3, max=100
Connection: Keep-Alive
Here's what it looks like when running through the squid proxy (note that "redirector.mysite.com" is not the site running squid or nginx):
http://redirector.mysite.com/?unicmd=g+yreka
GET /?unicmd=g+yreka HTTP/1.1
Host: redirector.mysite.com
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.5.9-1.fc12 Firefox/3.5.9
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
If-Modified-Since: Tue, 13 Apr 2010 05:21:02 GMT
HTTP/1.0 200 OK
Server: nginx/0.7.62
Date: Tue, 13 Apr 2010 05:21:10 GMT
Content-Type: text/html
Content-Length: 17865
Last-Modified: Tue, 13 Apr 2010 05:21:10 GMT
Accept-Ranges: bytes
X-Cache: MISS from jefferson
X-Cache-Lookup: HIT from jefferson:3128
Via: 1.1 jefferson:3128 (squid/2.7.STABLE6)
Connection: keep-alive
Proxy-Connection: keep-alive
It is basically working - but the URL http://redirector.mysite.com/?unicmd=g+yreka remains unchanged, while displaying the google page (mostly broken as it's using URLs relative to redirector.mysite.com)
I've experienced a similar thing with google results pages: when clicking to another page from google, I get a google URL, with the other site's content.
Sorry for the long post - many thanks if you've read this far! Any ideas?