Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

I think I understand your confusion. It works, but not as you were expecting.

SQUID does not actually redirect with the redirect_program directive, it rewrites. For example:

www.domain.com points to an IP that SQUID is available on

SQUID pipes the request through redirect_program

SQUID rewrites www.domain.com/dir1/ to server1 and www.domain.com/dir2/ to server2.

The client sees the same thing the whole time, as SQUID doesn't redirect.

Hopefully this is clear. If redirection is the functionality you desire, you might consider using Apache's mod_rewrite. It is more suitable for redirect functionality.

share|improve this answer
    
Thanks Warner. Actually the SQUID redirect seems fine - it's doing what I expected in the case where I visit a site that has the text that the redirect_program is looking for. The issue is not that I want a different redirect functionality from SQUID, it's that I don't want SQUID to interfere with HTTP redirects - which seems to be what I'm seeing. The redirector.mysite.com in my question should behave as normal (I believe it should... at least, I want it too...) –  EMiller Apr 18 '10 at 20:12
    
Would you be willing to identify the site? That might help clarify your quandary. I'll revisit tomorrow. –  Warner Apr 27 '10 at 4:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.