How to verify that Squid used as a reversed proxy is working?

瘦欲@ 提交于 2019-12-04 11:34:43

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.

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!