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. It runs on most available operating systems, including Windows and is licensed under the GNU GPL.
sudo apt-get update sudo apt-get upgrade sudo apt-get install squid
By default squid configuration is in file /etc/squid/squid.conf or /etc/squid3/squid.conf if you are using Squid3.
Caching tile.openstreetmap.org for your own domain tile.yoursite.com
This is basic steps to configure caching tile server:
- Defining port:
http_port 80 act-as-origin defaultsite=yoursite.com name=server vhost
- Parent cache:
cache_peer tile.openstreetmap.org parent 80 0 no-query no-digest originserver name=osmTiles forceddomain=tile.openstreetmap.org
- Access rules:
acl tiles dstdomain tile.yoursite.com cache_peer_access osmTiles allow tiles cache_peer_access osmTiles deny all http_access allow tiles http_access deny all
- Memory configuration(depending on your server capabilities):
cache_mem 256 MB maximum_object_size_in_memory 128 KB
- Cache directory to store not "hot" objects and anything else. Should be big enough. Maximum size(in megabytes) defines first number.
cache_dir aufs /var/spool/squid 8192 16 256
- Squid reconfiguration:
~> squid -k reconfigure
Thats all, now you have own tile server.
Caching tiles on localhost
If you wish to cache tiles on your PC, simply use the following /etc/squid/squid.conf or /etc/squid3/squid.conf:
cache_dir ufs /var/spool/squid 1024 16 256 # 1 GB of cache, may be increased
refresh_pattern -i \.(gif|png|jpg|jpeg|ico)$ 3600 90% 302400 # Cache at least 1H, at most half a week
Then restart squid:
# service squid restart
Configure your PC to use a proxy server for HTTP, you should set host to localhost and port to 3128.
You may check that squid is indeed caching tiles by checking size of its cache after 10 minutes:
sudo du -hs /var/spool/squid/