Search squid archive

Re: Reverse-Proxy/Cache for one backend webserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Frank Helmschrott wrote:
Hi all,

i'm rather new to squid so sorry if some of my questions sound a bit
dumb. I already read a lot about reverse proxy/caching with squid and
i'm sure squid is the right thing for my project.

My setup is a 2-server setup with one server with squid installed
beeing the proxy-server for a dynamic website delivered from server 2
using apache/php/mysql. The Website on server 2 is a news-style
website. Therefore the content isn't too dynamic making not only
graphics and css files cachable but also the news items itself.

For testing purposes i setup a small script and some dns stuff so that

dyn.testdomain.com resolves to the public ip of server 2
stat.testdomain.com resolves to the public ip of server 1 (squid)

The test script just contains a little php for the header (to set
expire, modified and stuff) and an output of the actual time to let me
see if it's fetched from server 2 or the cache.

After setting up everything i found to be important the basic proxy
stuff works apart from the caching and expiry stuff. It seems like
squid is fetching the original content whenever i reload the browser.

As Henrik pointed out reload causes fresh content to be forced through the proxy. Better just to set your browser non-caching and visit the page several times.

I've also already set refresh_pattern to match php files and override
the expiry set in the script and ignore reloads but unfortunately this
doesn't help. Here's what my squid conf looks like:
(below you'll find the php script i use for testing)

---
cache_mgr my@xxxxxxxxx
cache_dir ufs /var/cache/squid 4096 16 256
cache_mem 2048 MB
collapsed_forwarding on
minimum_expiry_time 120 seconds
http_port 127.0.0.1:80 vhost vport
cache_peer 127.0.0.2 parent 80 0 originserver default

By '2 servers' you mean you are simulating them yes? The two lines above will only work within the local host.


acl all src 0.0.0.0/0.0.0.0
acl QUERY urlpath_regex ^/admin \?

acl our_sites dstdomain .testdomain.com
http_access allow our_sites
no_cache allow QUERY

no_cache is obsolete. Allow is the default anyway. Best to just omit that and the ACL setting up QUERY in the first place.


acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
http_access allow manager localhost

cachemgr_passwd comet74 all

via on
header_access Via allow all
header_access Age deny all
header_access X-Cache deny all

refresh_pattern -i \.jpg$ 120 90% 240 override-expire override-lastmod
reload-into-ims ignore-reload
refresh_pattern -i \.jpeg$ 120 90% 240 override-expire
override-lastmod ignore-reload reload-into-ims
refresh_pattern -i \.gif$ 120 90% 240 override-expire override-lastmod
ignore-reload reload-into-ims
refresh_pattern -i \.png$ 120 90% 240 override-expire override-lastmod
ignore-reload reload-into-ims
refresh_pattern -i \.swf$ 120 90% 240 override-expire override-lastmod
ignore-reload reload-into-ims
refresh_pattern -i \.flv$ 120 90% 240 override-expire override-lastmod
ignore-reload reload-into-ims
refresh_pattern -i \.js$ 10 90% 20 override-expire override-lastmod
ignore-reload reload-into-ims
refresh_pattern -i \.css$ 10 90% 20 override-expire override-lastmod
ignore-reload reload-into-ims

It's really best to configure these age settings in the web server. That way they will duplicate out around the net, not just in your squid.


refresh_pattern -i \.php$ 10 90% 720 override-expire override-lastmod
ignore-reload ignore-no-cache


So where are the default patterns that handle general objects without expiry info?

---

<?php
//expire time in minutes
$expire = 3;

$exp_gmt = gmdate("D, d M Y H:i:s", time() + $expire * 60) ." GMT";
$mod_gmt = gmdate("D, d M Y H:i:s", getlastmod()) ." GMT";

// HTTP 1.0
header("Expires: " . $exp_gmt);
header("Last-Modified: " . $mod_gmt);

// HTTP 1.1
header("Cache-Control: public, max-age=" . $expire * 60);
//header("Pragma: ");
?>
<?php

$i = 1;

while ($i <= 3):
    echo $i++ . "<br />";
endwhile;

echo "miss at " . date('H:i:s');
?>

Any help is appreciated.


Amos
--
Please use Squid 2.7.STABLE2 or 3.0.STABLE6

[Index of Archives]     [Linux Audio Users]     [Samba]     [Big List of Linux Books]     [Linux USB]     [Yosemite News]

  Powered by Linux