How To‎ > ‎

Squid

Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator.

Using Squid as a HTTP accelerator

An HTTP accelerator, sometimes known as a reverse proxy, helps you offload the task of serving content from the main server by placing a proxy server in front of it and let the proxy server serve static content like images, css and javascript.

I got involved in a Microsoft SharePoint project where SharePoint, in my opinion, incorrectly marked some content as not cache-able by setting it to"private" and "max-age=0". I used Squid to override the cache settings based on how content was actually served and acceptable delays of content updates. It is against the HTTP specifications to do so, but bandwidth was more important then to be technical correct - and as the platform for the visitors was tightly controlled.

There where two main components to the setup: override caching policies from web server while making sure that the NTLM authentication works through the proxy.

Here is the configuration for the setup, modified to not reveal the original website.

http_port 80 accel defaultsite=michaelboman.org
cache_peer 192.168.1.16 parent 80 0 no-query login=PASS originserver connection-auth=on
visible_hostname michaelboman.org

client_persistent_connections on
server_persistent_connections on

acl all src 0.0.0.0/0.0.0.0
acl static_content urlpath_regex -i \.(jpg|gif|png|css|js|axd)

http_access allow all

cache_effective_user squid
cache_effective_group squid

# Do not tell the world that we are running squid
httpd_suppress_version_string on

# Remove the Caching Control header on content deemed static
header_access Cache-Control deny static_content

# Turn off ICP as we only have 1 proxy
icp_port 0

# See http://www.squid-cache.org/Versions/v2/2.6/cfgman/refresh_pattern.html
#refresh_pattern <regexp> <min> <percent> <max> <options>

# Overriding caching settings if nocache=true option is set
refresh_pattern nocache=true 0 0% 0

# Overriding caching settings if edit=yes option is set
refresh_pattern edit=yes 0 0% 0

# Cache profile images for 1 minute to 5 hours, but obey the cache settings
refresh_pattern MyProfile/Profile.Images 60 30% 18000

# TESTING: Caching everything like crazy
#refresh_pattern ^http: 600000 100% 700000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private ignore-auth

# Cache images for 4-5 hours, regardless what the server says
refresh_pattern .jpg 14400 50% 18000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private ignore-auth
refresh_pattern .gif 14400 50% 18000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private ignore-auth
refresh_pattern .png 14400 50% 18000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private ignore-auth

# Cache CSS and JavaScript for 4-5 days as well
refresh_pattern .css 14400 50% 18000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private ignore-auth
refresh_pattern .js  14400 50% 18000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private ignore-auth
refresh_pattern .axd 14400 50% 18000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private ignore-auth

# Cache all ASPX for 1-2 minutes  (forced)
#refresh_pattern .aspx 60   50% 120   override-expire override-lastmod ignore-no-cache
Comments