README
changeset 28 46e23ce07981
parent 27 bf206815c2ab
child 30 5cc836e06759
equal deleted inserted replaced
21:3510b50c6694 28:46e23ce07981
     3 =====
     3 =====
     4 
     4 
     5 What is volta?
     5 What is volta?
     6 --------------
     6 --------------
     7 
     7 
     8 Volta is a high performance, low resource URI rewriter for use with the
     8 Volta is a high-performance, low-resource URI rewriter for use with the
     9 Squid caching proxy server (http://www.squid-cache.org/.)  With it, you
     9 Squid caching proxy server (http://www.squid-cache.org/.)  With it, you
    10 can dynamically alter URI requests that pass through Squid based on
    10 can dynamically alter URI requests that pass through Squid based on
    11 various criteria.
    11 various criteria.
    12 
    12 
    13 It uses a state machine to parse URIs and rules, and a constant database
    13 It uses a state machine to parse URIs and rules, and a constant database
    34 Configuring squid
    34 Configuring squid
    35 -----------------
    35 -----------------
    36 
    36 
    37 You must enable url rewriting from within the squid.conf file.
    37 You must enable url rewriting from within the squid.conf file.
    38 
    38 
    39 	url_rewrite_program /usr/local/bin/volta
    39     url_rewrite_program /usr/local/bin/volta
    40 
    40 
    41 ... and that's it.  You may need some additional customization, like where
    41 ... and that's it.  You may need some additional customization, like where
    42 the volta database is stored on disk:
    42 the volta database is stored on disk:
    43 
    43 
    44 	url_rewrite_program /usr/local/bin/volta -f /var/db/squid/volta.db
    44     url_rewrite_program /usr/local/bin/volta -f /var/db/squid/volta.db
    45 
    45 
    46 Busy servers:
    46 Busy servers:
    47 
    47 
    48 Make sure rewrite_concurrency is disabled, volta is single threaded.
    48 Make sure rewrite_concurrency is disabled, volta is single threaded.
    49 Instead, just add more volta children.  They are lightweight, so load em
    49 Instead, just add more volta children.  They are lightweight, so load em
    50 up.  A proxy at my $DAYJOB is in use by around 450 people, and we get by
    50 up.  A proxy at my $DAYJOB is in use by around 450 people, and we get by
    51 nicely with 10 volta children.
    51 nicely with 10 volta children.
    52 
    52 
    53 	url_rewrite_concurrency 0
    53     url_rewrite_concurrency 0
    54 	url_rewrite_children 10
    54     url_rewrite_children 10
    55 
    55 
    56 
    56 
    57 Using volta
    57 Using volta
    58 -----------
    58 -----------
    59 
    59 
    60 See the INSTALL file for instructions on how to compile volta.
    60 See the INSTALL file for instructions on how to compile volta.
    61 
    61 
    62 Volta reads its rewrite rules from a local database.  You can create the
    62 Volta reads its rewrite rules from a local database.  You can create the
    63 rules in a text editor, then convert it to the database like so:
    63 rules in a text editor, then convert it to the database like so:
    64 
    64 
    65 	% volta -c rules.txt
    65     % volta -c rules.txt
    66 
    66 
    67 You'll be left with a "volta.db" file in the current directory.  Put it
    67 You'll be left with a "volta.db" file in the current directory.  Put it
    68 wherever you please, and use the -f flag to point to it.
    68 wherever you please, and use the -f flag to point to it.
    69 
    69 
    70 
    70 
    76 '#' character, so you can keep the ascii version of your rules well
    76 '#' character, so you can keep the ascii version of your rules well
    77 documented and in version control.
    77 documented and in version control.
    78 
    78 
    79 When compiling the ruleset into the database format, volta detects
    79 When compiling the ruleset into the database format, volta detects
    80 malformed rules and stops if there are any problems, leaving your
    80 malformed rules and stops if there are any problems, leaving your
    81 original database intact.  You can change the ruleset at any time while
    81 original database intact. You can change the ruleset and recompile the
    82 volta is running, and the new rules will take affect within about 10
    82 database at any time while volta is running, and the new rules will take
    83 seconds.  No need to restart squid!
    83 affect within about 10 seconds. No need to restart squid!
    84 
    84 
    85 There are two types of rules -- positive matches, and negative matches.
    85 There are two types of rules -- positive matches, and negative matches.
    86 Positive matches cause the rewrite, negative matches allow the original
    86 Positive matches cause the rewrite, negative matches allow the original
    87 request to pass.  Rule order is consistent, top-down, first match wins.
    87 request to pass.  Rule order is consistent, top-down, first match wins.
    88 Fields are separated by any amount of whitespace (spaces or tabs.)
    88 Fields are separated by any amount of whitespace (spaces or tabs.)
   100       rules per hostname.  Hostnames are compared without case sensitivity.
   100       rules per hostname.  Hostnames are compared without case sensitivity.
   101 
   101 
   102 
   102 
   103     Second field: the path to match.
   103     Second field: the path to match.
   104 
   104 
   105 	  This can be an exact match ('/path/to/something.html'), a regular
   105       This can be an exact match ('/path/to/something.html'), a regular
   106 	  expression ('\.(jpg|gif|png)$'), or a single '*' to match for any
   106       expression ('\.(jpg|gif|png)$'), or a single '*' to match for any
   107 	  path. Regular expressions are matches without case sensitivity.  There
   107       path. Regular expressions are matches without case sensitivity. There
   108 	  is currently no support for capturing, though this may be added in
   108       is currently no support for capturing, though this may be added in a
   109 	  a future release.
   109       future release.
   110 
   110 
   111 
   111 
   112     Third field: The redirect code and url to rewrite to.
   112     Third field: The redirect code and url to rewrite to.
   113 
   113 
   114       Any pieces of a url that are omitted are automatically replaced
   114       Any pieces of a url that are omitted are automatically replaced with
   115       with the original request's element -- the exception is a hostname,
   115       the original request's element -- the exception is a hostname, which
   116       which is required.  If you omit a redirect code, the URL rewrite is
   116       is required. If you omit a redirect code, the URL rewrite is
   117       transparent to the client.  You can attach a 301: or 302: prefix to
   117       transparent to the client. You can attach a 301: or 302: prefix to
   118       cause a permanent or temporary code to be respectively sent, instead.
   118       cause a permanent or temporary (respectively) redirect response to be
       
   119       sent, instead.
   119 
   120 
   120 
   121 
   121 ### Negative matches:
   122 ### Negative matches:
   122 
   123 
   123     First field: the hostname to match.
   124     First field: the hostname to match.
   124 
   125 
   125 	  See above -- all the same rules apply.
   126       See above -- all the same rules apply.
   126 
   127 
   127 
   128 
   128     Second field: the path to match.
   129     Second field: the path to match.
   129 
   130 
   130 	  See above -- all the same rules apply.
   131       See above -- all the same rules apply.
   131 
   132 
   132 
   133 
   133 	Third field: the 'negative' marker.
   134     Third field: the 'negative' marker.
   134 
   135 
   135 	  This is simply the '-' character, that signals to volta that this is
   136       This is simply the '-' character, that signals to volta that this is
   136 	  a negative matching rule.
   137       a negative matching rule.
   137 
   138 
   138 
   139 
   139 You can easily test your rules by running volta on the command line, and
   140 You can easily test your rules by running volta on the command line, and
   140 pasting URLs into it.   Boost the debug level (-d4) if you're having any issues.
   141 pasting URLs into it.   Boost the debug level (-d4) if you're having any issues.
   141 
   142 
   145 
   146 
   146 Rewrite all requests to Google to the SSL version:
   147 Rewrite all requests to Google to the SSL version:
   147 
   148 
   148     google.com * 302:https://www.google.com
   149     google.com * 302:https://www.google.com
   149 
   150 
   150 	This will redirect the request "http://www.google.com/search?q=test" to
   151     This will redirect the request "http://www.google.com/search?q=test" to
   151 	"https://www.google.com/search?q=test".
   152     "https://www.google.com/search?q=test".
   152 
   153 
   153 
   154 
   154 Transparently alter all uploaded images on imgur to be my face:  :)
   155 Transparently alter all uploaded images on imgur to be my face:  :)
   155 
   156 
   156 	i.imgur.com \.(gif|png|jpg)$ http://www.martini.nu/images/mahlon.jpg
   157     i.imgur.com \.(gif|png|jpg)$ http://www.martini.nu/images/mahlon.jpg
   157 
   158 
   158 
   159 
   159 Expand a local, non qualified hostname to a FQDN (useful alongside the
   160 Expand a local, non qualified hostname to a FQDN (useful alongside the
   160 'dns_defnames' squid setting to enforce browser proxy behaviors):
   161 'dns_defnames' squid setting to enforce browser proxy behaviors):
   161 
   162 
   162 	local-example * local-example.company.com
   163     local-example * local-example.company.com
   163 
   164 
   164 
   165 
   165 Cause all blog content except for 2011 posts to permanently redirect to
   166 Cause all blog content except for 2011 posts to permanently redirect to
   166 an archival page:
   167 an archival page:
   167 
   168 
   168 	martini.nu /blog/2011 -
   169     martini.nu /blog/2011 -
   169 	martini.nu /blog 301:martini.nu/content-archived.html
   170     martini.nu /blog 301:martini.nu/content-archived.html
   170 
   171 
   171 
       
   172 Turn off rewriting for specific network segment or IP address:
       
   173 
       
   174 	Squid has this ability built in -- see the 'url_rewrite_access' setting.
       
   175