奇怪的鱿鱼透明redirect行为

这是我第一次设置鱿鱼。 它运行一个redirect脚本,在html页面上执行一些文本search/replace,然后将它们保存到nginxpath中同一台机器上的一个位置 – 然后发出redirect到该URL(这是一个艺术项目:D)。

squid.conf中的相关行是

http_port 3128 transparent redirect_program /etc/squid/jefferson_redirect.py 

jefferson_redirect.py脚本基于以下脚本: http : //gofedora.com/how-to-write-custom-redirector-rewritor-plugin-squid-python/

问题

我得到奇怪的httpredirect行为。 例如,这是来自PHP脚本的正常请求/响应,它发出一个标题(“Location:”); – 302redirect:

 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 

这是通过squid代理运行时的样子(请注意,“redirector.mysite.com”不是运行squid或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 

它基本上是工作 – 但urlhttp://redirector.mysite.com/?unicmd=g+yreka保持不变,同时显示谷歌页面(大部分是因为它使用URL相对于redirector.mysite.com)

我经历了与谷歌结果页面类似的事情:当从谷歌点击到另​​一个页面时,我得到一个谷歌url,与其他网站的内容。

对不起,很长的文章 – 非常感谢,如果你已经读了这么多! 有任何想法吗?

我想我明白你的困惑。 它有效,但不是你所期望的。

SQUID实际上并没有用redirect_program指令redirect_program ,而是重写。 例如:

http://www.domain.com指向SQUID可用的IP

SQUID通过redirect_programpipe道请求

SQUID将www.domain.com/dir1/重写为server1,将www.domain.com/dir2/重写为server2。

客户始终看到同样的事情,因为SQUID不redirect。

希望这是明确的。 如果redirect是你想要的function,你可以考虑使用Apache的mod_rewrite。 它更适合redirectfunction。