0

同じマシンのphpアプリケーションの前でsquidをリバースキャッシュプロキシとして使用しようとしていますが、ユーザーがバックエンドにアクセスできないようにし、常に古いキャッシュをバックグラウンドでロードします。


ポート80でCentos 6.3(x86_64)でセルフコンパイルされたsquid 2.7-Stable9を使用しており、apache + phpはポート8000​​の同じマシンにあります。

apache+php 応答ヘッダーは、これを squid に送信します。

header('Cache-Control: max-age=10, stale-while-revalidate=15, stale-if-error=20');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

squid するページを要求すると、初回は再検証され、次回は常に古い状態で使用されますが、これは Firefox WebDevelopersTools 拡張機能のDISABLE CACHEキャッシュ オプションで機能します。

違いは、キャッシュが無効になっていない場合、クライアントはCache-control: max-age=0If-Modified-Sinceを送信し、squid は常にバックエンドに接続して再検証することです。

Squid 3.2 ではignore-ccを使用して期待どおりに動作しましたが、2.7 ではそのようなオプションはありません。

これが私のsquid.confです:

# http_port public_ip:port accel defaultsite= default hostname, if not provided
http_port 80 accel defaultsite=mydomain.com

# IP and port of your main application server (or multiple)
cache_peer 127.0.0.1 parent 8000 0 no-query originserver name=main
cache_peer_domain main mydomain.com

# Do not tell the world that which squid version we're running
httpd_suppress_version_string on

# Remove the Caching Control header for upstream servers
header_access Cache-Control deny all

# log all incoming traffic in Apache format
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
access_log /usr/local/squid/var/logs/squid.log combined all

cache_effective_user squid

refresh_pattern nocache=true 0 0% 0

icp_port 0

PHP アプリケーションでキャッシュ時間を選択し、再検証の待ち時間をユーザーに見せないようにしたいので、stale-while-revalidate でバージョン 2.7 を使用しています。


キャッシュを有効にしたリクエストの例:

GET /some-page HTTP/1.1
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1 FirePHP/0.7.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
x-insight: activate
If-Modified-Since: Thu, 11 Oct 2012 10:14:52 GMT
Cache-Control: max-age=0

HTTP/1.0 200 OK
Date: Thu, 11 Oct 2012 10:29:31 GMT
Server: Apache/2.2.22 (PowerStack)
Last-Modified: Thu, 11 Oct 2012 10:29:32 GMT
Content-Type: text/html; charset=UTF-8
X-Cache: MISS from localhost
X-Cache-Lookup: HIT from localhost:80
Via: 1.1 localhost:80 (squid)
Connection: close

キャッシュが無効になっている例(私がしたいこと):

GET /some-page HTTP/1.1
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1 FirePHP/0.7.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
x-insight: activate

HTTP/1.0 200 OK
Date: Thu, 11 Oct 2012 10:36:53 GMT
Server: Apache/2.2.22 (PowerStack)
Last-Modified: Thu, 11 Oct 2012 10:36:53 GMT
Content-Type: text/html; charset=UTF-8
Age: 2
Content-Length: 16725
X-Cache: HIT from localhost
X-Cache-Lookup: HIT from localhost:80
Via: 1.1 localhost:80 (squid)
Connection: keep-alive
4

1 に答える 1

0

ここで説明されている解決策: squid 2.7 で 3.1 機能「ignore-cc」を使用する方法


さて、すべての代替案を試した後、ソース コードを修正して機能を実装しました。

Squid-2.7-stable9でファイルsrc/refresh.c : 282を変更しました。

282:    if (request) {

為に

282:    if (request && FALSE) {

3.X では、ignoreCc を実装するために次のようなことを行います。

269:    if (request && !request->flags.ignore_cc) {

期待どおりに動作しました。

于 2012-10-15T07:03:40.037 に答える