Squid reverse proxy con caching

June 21, 2009 · 629 views · Print This Post Print This Post · Email This Post Email This Post

Oggi ho fatto qualche prova con squid in modalità reverse proxy con caching, non sò se ve ne siete accorti ma il blog è stato un po su e un po giù tra le 15.30 e le 16.30. Il risulato non mi è sembrato proprio entusiasmanete, le pagine del blog ci mettevano una cifra di tempo a caricarsi.. Comunque magari è stato solo un momento sfigato perchè il server delle immagini mi si era impallato e poi il server di front-end aveva la memoria a tappo e di sicuro smanettarci sopra non ha migliorato la situazione.. Comuque domani ci riprovo di sicuro, secondo me le performance dovrebbero migliorare con un reverse proxy che restituisce pagine cachate..


Scrivo qui la configurazione standard per far funzionare squid come reverse proxy, in pratica basta installare squid e poi copiare e incollare quanto segue nel file squid.conf. Ovviamente dovete sostituire l’ip del vostro server e il nome del dominio..
Ah per l’installazione su debian basta un banale:

apt-get install squid

Ecco la configurazione per il caching con squid..

### inizio ###

cache_mgr root

# Basic parameters
visible_hostname www.example.com

# This line indicates the server we will be proxying for
http_port 80 defaultsite=www.example.com vhost

# And the IP Address for it – adjust the IP and port if necessary
cache_peer 127.0.0.1 parent 8080 0 no-query originserver login=PASS

acl apache rep_header Server ^Apache
broken_vary_encoding allow apache

# Where the cache files will be, memory and such
cache_dir ufs /var/spool/squid 10000 16 256
cache_mem 256 MB
maximum_object_size_in_memory 128 KB

# Log locations and format
#logformat common %>a %ui %un [%tl] “%rm %ru HTTP/%rv” %Hs %<st %Ss:%Sh
logformat combined %>a %ui %un [%tl] “%rm %ru HTTP/%rv” %Hs %<st “%{Referer}>h” “%{User-Agent}>h” %Ss:%Sh

access_log /var/log/squid/access.log combined

# Example how to configure Squid to not log certain requests
#acl dontlog urlpath_regex ^\/monit\/token$
#acl dontlog urlpath_regex ^\/server-status$
#acl dontlog urlpath_regex ^\/admedia\/reste_300×250.php$
#acl dontlog urlpath_regex ^\/admedia\/reste_120×600.php$
#acl dontlog urlpath_regex ^\/admedia\/reste_728×90.php$
#acl dontlog urlpath_regex ^\/geoip\/rectangle_forum_postbit.html$
#acl dontlog urlpath_regex ^\/geoip\/banner_iframe.php
#acl dontlog urlpath_regex ^\/js\/amazon.js
#acl dontlog urlpath_regex .js$
#acl dontlog urlpath_regex .css$
#acl dontlog urlpath_regex .png$
#acl dontlog urlpath_regex .gif$
#acl dontlog urlpath_regex .jpg$
#access_log /var/log/squid/access.log combined !dontlog

cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
logfile_rotate 10
## put this in crontab to rotate logs at midnight:
## 0 0 * * * /usr/sbin/squid -k rotate &> /dev/null

hosts_file /etc/hosts

# Basic ACLs
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl Safe_ports port 80
acl purge method PURGE
acl CONNECT method CONNECT

http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access allow localhost
http_access allow all
http_access allow all
http_reply_access allow all

icp_access allow all

cache_effective_group proxy

coredump_dir /var/spool/squid

forwarded_for on

emulate_httpd_log on

redirect_rewrites_host_header off

buffered_logs on

# Do not cache cgi-bin, ? urls, posts, etc.
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
acl POST method POST
no_cache deny QUERY
no_cache deny POST

# Example how to configure Squid to not cache certain URLs
#acl adminurl urlpath_regex ^/myadminpanel
#no_cache deny adminurl
#acl phpmyadminurl urlpath_regex ^/phpmyadmin
#no_cache deny phpmyadminurl

### fine ###

Questa configurazione l’ho presa da questo link:

http://www.howtoforge.com/how-to-set-up-a-caching-reverse-proxy-with-squid-2.6-on-debian-etch

OVviamente sono spiegate un mucchio di altre cose, come la gestione dei log
Oggi ho fatto solo una prova veloce e ha funzionato, non veloce come mi aspettavo ma ha funzionato…

Domani provo a limarla,cioè a togliere tutto quello che non serve e a lasciare l’essenziale. Comunque il reverse proxy che sto utilizzando adesso, (pound) funziona benissimo anche se cache e non mi sembra per niente male.. Scriverò anche un post su pound..
Comunque al solito se avete suggerimenti su reverse proxy con cache ditemi tutto nei commenti.. domani seguiranno altri test hehe

Vota l’articolo
(No Ratings Yet)
Loading ... Loading ...

Condividi l'articolo:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Twitter

Link consigliati

Newsletter e Feed

Ti e' piaciuto questo articolo? allora iscrivi alla newsletter, riceverai ogni nuovo post via mail!!
Loading...Loading...


Se preferiferisci i feed ricordati di iscriverti ai miei Feed!

Commenti

Lascia un Commento




Protezione antispam: Somma di quattro + sette ?