如何验证用作反向代理的 Squid 是否正常工作?

发布于 2024-07-15 11:36:02 字数 2576 浏览 5 评论 0原文

我们希望减少其中一台 Web 服务器的负载,并且正在使用配置为反向代理的鱿鱼运行一些测试。

配置在下面的备注中:

http_port 80 accel defaultsite=original.server.com

cache_peer original.server.com 父级 80 0 无查询 originserver name=myAccel

acl our_sites dstdomain .contentpilot.net

http_access 允许 our_sites

cache_peer_access myAccel 允许 our_sites

cache_peer_access myAccel 拒绝全部

我们遇到的情况是服务器几乎总是返回 TCP_MISS。

1238022316.988     86 69.15.30.186 TCP_MISS/200 797 GET http://original.server.com/templates/site/images/topnav_givingback.gif - FIRST_UP_PARENT/myAccel -
1238022317.016     76 69.15.30.186 TCP_MISS/200 706 GET http://original.server.com/templates/site/images/topnav_diversity.gif - FIRST_UP_PARENT/myAccel -
1238022317.158     75 69.15.30.186 TCP_MISS/200 570 GET http://original.server.com/templates/site/images/topnav_careers.gif - FIRST_UP_PARENT/myAccel -
1238022317.344     75 69.15.30.186 TCP_MISS/200 2981 GET http://original.server.com/templates/site/js/home-search-personalization.js - FIRST_UP_PARENT/myAccel -
1238022317.414     85 69.15.30.186 TCP_MISS/200 400 GET http://original.server.com/templates/site/images/submenu_arrow.gif - FIRST_UP_PARENT/myAccel -
1238022317.807     75 69.15.30.186 TCP_MISS/200 2680 GET http://original.server.com/templates/site/js/homeMakeURL.js - FIRST_UP_PARENT/myAccel -
1238022318.666   1401 69.15.30.186 TCP_MISS/200 103167 GET http://original.server.com/portalresource/lookup/wosid/intelliun-2201-301/image2.jpg - FIRST_UP_PARENT/myAccel image/pjpeg
1238022319.057   1938 69.15.30.186 TCP_MISS/200 108021 GET http://original.server.com/portalresource/lookup/wosid/intelliun-2201-301/image1.jpg - FIRST_UP_PARENT/myAccel image/pjpeg
1238022319.367     83 69.15.30.186 TCP_MISS/200 870 GET http://original.server.com/templates/site/images/home_dots.gif - FIRST_UP_PARENT/myAccel -
1238022319.367     80 69.15.30.186 TCP_MISS/200 5052 GET http://original.server.com/templates/site/images/home_search.jpg - FIRST_UP_PARENT/myAccel -
1238022319.368     88 69.15.30.186 TCP_MISS/200 5144 GET http://original.server.com/templates/site/images/home_continue.jpg - FIRST_UP_PARENT/myAccel -
1238022319.368     76 69.15.30.186 TCP_MISS/200 412 GET http://original.server.com/templates/site/js/showFooterBar.js - FIRST_UP_PARENT/myAccel -
1238022319.377    100 69.15.30.186 TCP_MISS/200 399 GET http://original.server.com/templates/site/images/home_arrow.gif - FIRST_UP_PARENT/myAccel -

我们已经尝试删除所有缓存。 有任何想法吗。 难道我的网站每次都会标记一些不同的内容,即使自上次代理请求以来它没有发生变化?

We want to decrease the load in one of our web servers and we are running some tests with squid configured as a reverse proxy.

The configuration is in the remarks below:

http_port 80 accel defaultsite=original.server.com

cache_peer original.server.com parent 80 0 no-query originserver name=myAccel

acl our_sites dstdomain .contentpilot.net

http_access allow our_sites

cache_peer_access myAccel allow our_sites

cache_peer_access myAccel deny all

The situation we are having is that pretty much the server is returning TCP_MISS almost all the time.

1238022316.988     86 69.15.30.186 TCP_MISS/200 797 GET http://original.server.com/templates/site/images/topnav_givingback.gif - FIRST_UP_PARENT/myAccel -
1238022317.016     76 69.15.30.186 TCP_MISS/200 706 GET http://original.server.com/templates/site/images/topnav_diversity.gif - FIRST_UP_PARENT/myAccel -
1238022317.158     75 69.15.30.186 TCP_MISS/200 570 GET http://original.server.com/templates/site/images/topnav_careers.gif - FIRST_UP_PARENT/myAccel -
1238022317.344     75 69.15.30.186 TCP_MISS/200 2981 GET http://original.server.com/templates/site/js/home-search-personalization.js - FIRST_UP_PARENT/myAccel -
1238022317.414     85 69.15.30.186 TCP_MISS/200 400 GET http://original.server.com/templates/site/images/submenu_arrow.gif - FIRST_UP_PARENT/myAccel -
1238022317.807     75 69.15.30.186 TCP_MISS/200 2680 GET http://original.server.com/templates/site/js/homeMakeURL.js - FIRST_UP_PARENT/myAccel -
1238022318.666   1401 69.15.30.186 TCP_MISS/200 103167 GET http://original.server.com/portalresource/lookup/wosid/intelliun-2201-301/image2.jpg - FIRST_UP_PARENT/myAccel image/pjpeg
1238022319.057   1938 69.15.30.186 TCP_MISS/200 108021 GET http://original.server.com/portalresource/lookup/wosid/intelliun-2201-301/image1.jpg - FIRST_UP_PARENT/myAccel image/pjpeg
1238022319.367     83 69.15.30.186 TCP_MISS/200 870 GET http://original.server.com/templates/site/images/home_dots.gif - FIRST_UP_PARENT/myAccel -
1238022319.367     80 69.15.30.186 TCP_MISS/200 5052 GET http://original.server.com/templates/site/images/home_search.jpg - FIRST_UP_PARENT/myAccel -
1238022319.368     88 69.15.30.186 TCP_MISS/200 5144 GET http://original.server.com/templates/site/images/home_continue.jpg - FIRST_UP_PARENT/myAccel -
1238022319.368     76 69.15.30.186 TCP_MISS/200 412 GET http://original.server.com/templates/site/js/showFooterBar.js - FIRST_UP_PARENT/myAccel -
1238022319.377    100 69.15.30.186 TCP_MISS/200 399 GET http://original.server.com/templates/site/images/home_arrow.gif - FIRST_UP_PARENT/myAccel -

We already tried removing all the cache memory. Any ideas. Could it be that my web site is marking some of the content different each time even though it has not change since the last time it was requested by the proxy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花辞树 2024-07-22 11:36:02

源服务器(Web 服务器)随您的内容发回哪些标头? 为了能够被鱿鱼缓存,我相信您通常必须在响应标头中指定 Last-Modified 或 ETag。 Web 服务器通常会针对静态内容自动执行此操作,但如果您的内容是动态提供的(即使来自静态源),那么您必须确保它们存在,并处理请求标头,例如 If-Modified-Since 和 If-无匹配。

另外,由于您随后有关会话的问题指出了这个问题,因此响应中是否出现“Vary”标头? 例如,“Vary: Cookie”告诉缓存内容可以根据请求中的 Cookie 标头而变化:因此静态内容希望将其删除。 但是,如果存在会话,您的 Web 服务器可能会将其添加到所有请求中,无论所提供的数据的静态/动态性质如何。

根据我的经验,对 HTTP 标头进行一些实验来了解对缓存的影响是非常有益的:我记得发现解决方案并不总是显而易见的。

What headers is the origin server (web server) sending back with your content? In order to be cacheable by squid, I believe you generally have to specify either a Last-Modified or ETag in the response header. Web servers will typically do this automatically for static content, but if your content is being dynamically served (even if from a static source) then you have to ensure they are there, and handle request headers such as If-Modified-Since and If-None-Match.

Also, since I got pointed to this question by your subsequent question about sessions--- is there a "Vary" header coming out in the response? For example, "Vary: Cookie" tells caches that the content can vary according to the Cookie header in the request: so static content wants to have that removed. But your web server might be adding that to all requests if there is a session, regardless of the static/dynamic nature of the data being served.

In my experience, some experimentation with the HTTP headers to see what the effects are on caching is of great benefit: I remember finding that the solutions were not always obvious.

半窗疏影 2024-07-22 11:36:02

检查 firefox 中使用wireshark或firebug返回的标头(后者更容易刺激,但如果您最终需要的话,前者将为您提供更多低级信息)。

在响应标头中查找这些项目(单击“网络”视图中的项目将其展开并查看请求和响应标头):

  • 最后修改日期 -> 如果没有设置为过去的合理时间,则不会缓存
  • Etags -> 如果每次请求相同的项目时这些都发生变化,那么它将被重新获取
  • Cache-Control -> 来自客户端的 max-age=0 的请求将(我相信)每次都会请求页面的新副本
  • (编辑) Expires header -> 如果这是过去设置的(即总是过期),那么squid将不会缓存它

正如araqnid所建议的,HTTP标头可以对代理认为它可以缓存的内容产生巨大的影响。 如果您的后端使用 apache,则测试不通过任何 PHP 或其他应用程序层提供的静态文件是否可缓存。

另外,检查squid的maximum_object_size和minimum_object_size设置是否设置为合理的值(默认值是4Mb和0kb,这应该没问题),并且最大缓存项年龄也设置为合理。
(参见http://www.visolve.com/squid/squid30/cachesize。 php#maximum_object_size 对于此设置和其他设置)

Examine the headers returned with wireshark or firebug in firefox (the latter is easier to prod around but the former will give you more low-level information if you end up needing that).

Look for these items in the Response Headers (click on an item in the `Net' view to expand it and see request and response headers):

  • Last-Modified date -> if not set to a sensible time in the past then it won't be cached
  • Etags -> if these change every time the same item is requested then it will be re-fetched
  • Cache-Control -> Requests from the client with max-age=0 will (I believe) request a fresh copy of the page each time
  • (edit) Expires header -> If this is set in the past (i.e. always expired) then squid will not cache it

As suggested by araqnid, the HTTP headers can make a huge difference to what the proxy will think it can cache. If your back-end is using apache then test that static files served without going via any PHP or other application layer are cacheable.

Also, check that the squid settings for maximum_object_size and minimum_object_size are set to sensible values (the defaults are 4Mb and 0kb, which should be fine), and maximum cache item ages are also set sensibly.
(See http://www.visolve.com/squid/squid30/cachesize.php#maximum_object_size for this and other settings)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文