How To Set Up A Caching Reverse Proxy With Squid 2.6 On Debian Etch
How To Set Up A Caching Reverse Proxy With Squid 2.6 On Debian EtchVersion 1.0 This article explains how you can set up a caching reverse proxy with Squid 2.6 in front of your web server on Debian Etch. If you have a high-traffic dynamic web site that generates lots of database queries on each request, you can decrease the server load dramatically by caching your content for a few minutes or more (that depends on how often you update your content). I do not issue any guarantee that this will work for you!
1 Preliminary NoteIn this guide I will call the web site that I want to cache www.example.com, and it's running on Apache2. I will install Squid on the same server and configure Apache to listen on port 8080 and Squid on port 80 so that all HTTP requests go to Squid which then passes them on to Apache (unless it can satisfy the request from its cache). Of course, you are free to install Squid on another system - you could then let Apache run on port 80.
2 Preparing The Backend Web Server (Apache)Squid will pass on the original user's IP address in a field called X-Forwarded-For to the backend web server (Apache). Of course, the backend web server should log the original user's IP address in its access log instead of the IP address of our Squid proxy. Therefore we must modify the LogFormat line in /etc/apache2/apache2.conf and replace %h with %{X-Forwarded-For}i: vi /etc/apache2/apache2.conf
Next we open /etc/apache2/ports.conf... vi /etc/apache2/ports.conf ... and change the port that Apache should listen on to 8080:
Afterwards we restart Apache: /etc/init.d/apache2 restart
3 Installing And Configuring SquidSquid can be installed as follows: apt-get install squid Next we make a backup of the original squid.conf file (/etc/squid/squid.conf): cd /etc/squid/ squid.conf_orig is more then 4000 lines long - it contains all valid Squid 2.6 configuration options together with lots of comments. Although this is pretty much to read, you should definitely take the time to study it! Now we can create a squid.conf file for our server: vi squid.conf
This is standard stuff. Make sure you adjust the hostname and IP address, if necessary. The login=PASS option in the cache_peer line makes that .htaccess authentication is passed through the cache. I've added some (commented out) lines that show how you can configure Squid to not log certain requests in its access log and how to tell it to not cache certain URLs. This configuration assumes that all your users are seeing the same, i.e., you don't have logged-in users that should see something different than anonymous users. If you have logged-in users that should not see cached content, read on - I'll come to that in a moment (chapter 5). Now change the permissions of squid.conf and restart Squid: chmod 600 squid.conf
3.1 Log RotationLet's assume that you want Squid to start new log files (access.log, cache.log, store.log) each day at midnight because your log analysis program needs it that way. To do this, you need the logfile_rotate directive in squid.conf (see above) with a number of old log files to keep (e.g., if you specify 10, Squid would keep the last ten log files, access.log.0 - access.log.9, cache.log.0 - cache.log.9, and store.log.0 - store.log.9). In order to tell Squid to start a new log file, we must create the following cron job that runs each day at midnight: crontab -e
|



Recent comments
16 hours 54 min ago
19 hours 49 min ago
21 hours 3 min ago
22 hours 27 min ago
1 day 5 min ago
1 day 1 hour ago
1 day 2 hours ago
1 day 18 hours ago
1 day 19 hours ago
1 day 23 hours ago