Building a self made CDN based on Squid server , is a very simple task
all we need to do is tell squid what domains we want to serve , and where
to get its origin files .
The main idea of CDN is to act as reverse proxy for the origin servers ,
most of the cdn providers out works in the same way as we are about to do .
the first step is to prepare the server . in this example i used a clean squid.conf
for the simplicity of things , this was tested on squid version 3.1 but can work with older versions
as well with small changes . so install squid server , then edit your squid.conf file
we are going to proxy 2 domains www.example.com and images.example.com .
in order to let squid know the origin ip we are going to use 2 more domains
orig-www.example.com orig-images.example.com . and now lets explain how it would work in general
1. user request www.example.com
2. DNS resolve CNAME cdn.www.example.com
3. squid get request for domain www.example.com and look for its origin peer origin-www.example.com
4. squid reverse proxy www.example.com by delivering the files
from origin-www.example.com back to the user while caching it for the next request .
So now we need to edit squid.conf and make it act as acceleration ( what use to be transparent proxy )
and listen on port 80
http_port 80 accel ignore-cc defaultsite=www.example.com vhost acl mysite1 dstdomain www.example.com acl mysite2 dstdomain images.example.com cache_peer orig-www.example.com parent 80 0 no-query originserver name=wwwip cache_peer orig-images.example.com parent 80 0 no-query originserver name=imgip cache_peer_access wwwip allow mysite1 cache_peer_access imgip allow mysite2 http_access allow mysite1 http_access allow mysite2 visible_hostname cdn.example.com cache_mem 1 GB