ActiveSfMirroringMedia

This page describes how to use another server, one or more, to mirror the media for one or more sites running in one production server. This is ideal when the production server (Stray) is overloaded or you need to split the bandwidth usage among several servers.

Pittsburgh Indymedia was using this and because the bandwidth problems on Stray we need to mirror the Media of sites hosted there.

All credits goes to MattToups

MatRiseup Jul-2007

Table of content :

Needed components

  • Main server running sf-active
  • Second server running squid
  • New DNS records

Squid configuration

You need one server with squid installed and running. This is the squid.conf from the mirror running squid only. Squid is running in port 80.

http_port 213.130.163.58:80 vhost defaultsite=argentina.indymedia.org

cache_peer 208.69.42.191 parent 80 0 no-query
visible_hostname cache.argentina.indymedia.org

acl all src 0.0.0.0/0.0.0.0
http_access allow all

### stuff below can be tweaked depending on the server used
cache_dir ufs /usr/local/squid/cache 20000 16 256
cache_mem 1024 MB
maximum_object_size 512 MB

### stuff below is for anonymizing
logformat common %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st %Ss:%Sh
logformat common-noip 0.0.0.0 %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st %Ss:%Sh
access_log /usr/local/squid/logs/access.argentina.log common-noip
forwarded_for off

Apache virtualhosts

Apache main virtualhost

You need to add one or more lines in the main site virtualhost for the files you want to redirect to media.argentina.indymedia.org for this files be serverd by the squid mirror. In the lines below we are serving all the files from /im/* /images/* and /uploads/*

Those are the biggest files from the site, leaving the main production server to only server the php files.

RedirectMatch /im/(.*)$ http://media.argentina.indymedia.org/im/$1
RedirectMatch /images/(.*)$ http://media.argentina.indymedia.org/images/$1
RedirectMatch /uploads/(.*)$ http://media.argentina.indymedia.org/uploads/$1

Apache new virtualhost

You need to create a new virtualhost in the main production server to attend the requests of the squid mirror. This is the new virtualhost we use for Indymedia Argentina.

<VirtualHost *:80>
        ServerAdmin argentina(a)indymedia.org
        DocumentRoot /home/argentina/website
        ServerName media.argentina.indymedia.org
        SetEnv SITE_NAME argentina
        CustomLog /usr/local/apache2/logs/argentina.indymedia.org-access.log indy
        ErrorLog  /dev/null
        <Directory /home/argentina/website>
                Options Multiviews FollowSymlinks
                AllowOverride All
                Order Deny,Allow
                Allow from all
        </Directory>
  Redirect ^/$ http://argentina.indymedia.org
</VirtualHost>

Apache Expires Module

You will probably like to use the Apache Module mod_expires which can be used to set a maximum age on your content. Say you change an image for a feature, the cache should change that in X time. Note that if you use a modification date based setting, the Expires header will not be added to content that does not come from a file on disk.

ExpiresDefault "access plus 3 hours"

You may want to override the default with different values per mediatype: Example configuration:

# enable expirations
ExpiresActive On
# expire GIF images after a 12 hours in the client's cache
ExpiresByType image/gif A43200
# expire JPEG images 3 hours after the latest modification
ExpiresByType image/jpeg M10800

New DNS Record

You need to create the dns record for media.*.indymedia.org. Change * with your domain or subdomain where the main site is running.

Enjoy

If everything goes fine now you have all the media served from the squid mirror.

-- MatRiseup - 15 Jul 2007 -- KwadroNaut - 27 Aug 2007 added info about expiration done by apache
Topic revision: r3 - 27 Aug 2007, KwadroNaut
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback