NOTICE: You are viewing a page of the openwetware wiki. Our "dewikify" feature makes a wiki page appear as a normal web page. In April 2017, this feature will GO AWAY and this URL will redirect to the source URL on our wiki. We're sorry for the inconvenience.


Why Squid?

Squid is a high-performance proxy server that can also be used as a HTTP accelerator for the webserver. Explained in layman terms, Squid will store a copy of the pages served by webserver and the next time the same page is requested, Squid will serve the copy. This process is called "caching" and it removes the need for the webserver to regenerate that same page again, resulting in a tremendous performance boost for the webserver.

Since MediaWiki websites are generated dynamically entirely, there is a substantial performance gain in running Squid as a HTTP accelerator for your webserver. In fact, sites like Wikipedia use several Squid caches to enhance their performance.

Because of this performance gain, MediaWiki has been designed to integrate closely with Squid. For example, MediaWiki will notify Squid when a page should be purged from the cache in order to be regenerated.

The architecture

How to set up a combo of Squid, Apache and MediaWiki on a single server is outlined below. It is possible to use a more complex caching strategy or use different port numbers and IP-addresses, but for this simple example we strive for the following single-server architecture:

Outside world <--->


Squid accelerator


Apache webserver

To the outside world, Squid will seem to act as the webserver. In reality, it passes on requests to the Apache webserver, but only when necessary. Apache runs on the same server, but it only listens to requests from localhost ( Rest assured, running both services on port 80 will not cause conflicts, since both services are bound to different IP addresses.

Setting it up like this means Apache cannot be accessed from the outside world directly, only through Squid. Using this configuration, Apache can only be accessed directly from the console of the server it is running on. For testing and troubleshooting purposes to bypass Squid completely, one can use Elinks ( and browse to

Configuring Squid 2.5

Due to its versatility Squid has a very large "squid.conf" configuration file. There are however only a few settings relevant when using Squid in accelerator mode. See below section for 2.6 configuration.

First and foremost, Squid needs to know which IP-address and port to listen to:

# Use your own external IP-address

Then, Squid needs to know what host to accelerate. In this case, Apache will be listening to port 80 on the localhost:

#Accelerating only Apache on localhost
httpd_accel_port 80
httpd_accel_single_host on

If you run virtual domains, you also want this:

httpd_accel_uses_host_header on

For Squid 2.6:

http_port transparent vhost defaultsite=<sitename>
cache_peer parent 80 3130 originserver 

Now it is time to define what may be accessed and from where. This is done by defining access control lists ("acl"s) and allowing or denying http_access. Basically, there are a few things we need to allow in order for our setup to work:

  1. Access to the web port (80) must be allowed
  2. For maintenance purposes access to the cachemanager will be allowed for the localhost
  3. MediaWiki's requests to purge pages will be allowed for the localhost

All other access will be denied. This results in the following configuration:

# Minimum setup
acl all src
acl manager proto cache_object
acl localhost src
# Allow access to the web ports
acl web_ports port 80
http_access allow web_ports
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager
# Allow purge
acl purge method PURGE
http_access allow purge localhost
http_access deny purge
# And finally deny all other access to this proxy
http_access deny all

Note: There is a mention in the function sendCacheControl() in OutputPage.php of more rules that should be added in to replace Cache-Control headers [1].

Configuring Apache

The Apache webserver now needs to be configured to listen only to the localhost port 80. The file httpd.conf should contain the following line:


and if you are using virtual hosts also lines like:



Configuring MediaWiki

When configuring MediaWiki act as if there is no Squid. Meaning, use the servername the outside world would use instead of the internal IP-address. E.g., use "" for servername instead of "".

Since Squid is doing the requests from localhost, Apache will receive "" as the direct remote address. However, as Squid forwards the requests to Apache, it adds the "X-Forwarded-For" header containing the direct remote address as received by Squid. This way the remote address from the outside world is preserved.

By default MediaWiki will use the direct remote address for changes etcetera, so it must be configured to use the "X-Forwarded-For" header instead in order to function correctly. Make sure the LocalSettings.php file contains the following lines:

$wgUseSquid = true;
$wgSquidServers = array('');

See also Manual:Configuration settings#Squid for all configuration settings related to squid.

Some notes

In this setup, Squid will shield off most of the traffic to Apache. Therefore, if you need reliable web statistics from a statistics package like e.g. AWStats, you will need to set it up to analyze Squid's access_log instead of Apache's.

If you plan on balancing between multiple servers, plan on changing your session.save_path PHP configuration to be shared through all your backend Apache servers, see this e-mail and info on NFS.

Squid 2.6 Configuration Settings

Squid 2.6 has simplified the http accelerator configuration, and these settings should work:

http_port <Your external IP>:80 defaultsite=<Your DNS sitename> vhost
cache_peer parent 80 0 no-query round-robin name=wiki
acl mySites dstdomain <Your DNS sitename> <any other vhosts>
cache_peer_access wiki allow mySites
cache_peer_access wiki deny all
http_access allow mySites

Also, a URL rewriter isn't necessary for redirecting from *.com and *.net domains to your *.org domain if you have $wgServer set in your LocalSettings.php since Mediawiki will take care of this for you.

Apache 2.x-Logfile Settings

The Apache Webserver is only seeing "" Within Apache you can use the Parameter "X-Forwarded-for" which is provided by Squid e.g. within a custom logfile format. The sample below is similar to the "combined" one.



LogFormat "%{X-Forwarded-for}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" cached


forwarded_for on