Book Image

Squid Proxy Server 3.1: Beginner's Guide

Book Image

Squid Proxy Server 3.1: Beginner's Guide

Overview of this book

Squid Proxy Server enables you to cache your web content and return it quickly on subsequent requests. System administrators often struggle with delays and too much bandwidth being used, but Squid solves these problems by handling requests locally. By deploying Squid in accelerator mode, requests are handled faster than on normal web servers making your site perform quicker than everyone else's! Squid Proxy Server 3.1 Beginner's Guide will help you to install and configure Squid so that it is optimized to enhance the performance of your network. The Squid Proxy Server reduces the amount of effort that you will have to put in, saving your time to get the most out of your network. Whether you only run one site, or are in charge of a whole network, Squid is an invaluable tool that improves performance immeasurably. Caching and performance optimization usually requires a lot of work on the developer's part, but Squid does all that for you. This book will show you how to get the most out of Squid by customizing it for your network. You will learn about the different configuration options available and the transparent and accelerated modes that enable you to focus on particular areas of your network. Applying proxy servers to large networks can be a lot of work as you have to decide where to place restrictions and who should have access, but the straightforward examples in this book will guide you through step by step so that you will have a proxy server that covers all areas of your network by the time you finish the book.
Table of Contents (20 chapters)
Squid Proxy Server 3.1 Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – writing our own template for a URL redirector


Now, let's have a look at an example URL redirector program in Python, which can be extended to fit any scenario:

#!/usr/bin/env python

import sys

def redirect_url(line, concurrent):
  list = line.split(' ')
  # 1st or 2nd element of the list 
  # is the URL depending on concurrency
  if concurrent:
    old_url = list[1]
  else:
    old_url = list[0]

  # Do remember that the new_url 
  # should contain a '\n' at the end.
  new_url = '\n'
  # Take the decision and modify the url if needed
  if old_url.endswith('.avi'):
    # Rewrite example
    new_url = 'http://example.com/' + new_url
  elif old_url.endswith('.exe'):
    # Redirect example
    new_url = '302:http://google.co.in/' + new_url
  return new_url

def main(concurrent = True):
  # the format of the line read from stdin with concurrency is
  # ID URL ip-address/fqdn ident method myip=ip myport=port
  # and with concurrency disabled is
  # URL ip-address/fqdn ident...