<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>D90 Tools &#38; Techniques &#187; Squid</title>
	<atom:link href="http://www.d90.us/toolbox/category/web-hosting-tools/squid/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.d90.us/toolbox</link>
	<description>So I can remember how I did stuff in the future...</description>
	<lastBuildDate>Fri, 26 Nov 2010 20:08:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Squid handling http &#8211;&gt; https redirects</title>
		<link>http://www.d90.us/toolbox/2009/05/29/squid-handling-http-https-redirects/</link>
		<comments>http://www.d90.us/toolbox/2009/05/29/squid-handling-http-https-redirects/#comments</comments>
		<pubDate>Sat, 30 May 2009 01:35:48 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Sysadmin Tools]]></category>

		<guid isPermaLink="false">http://www.d90.us/toolbox/?p=95</guid>
		<description><![CDATA[In configuring Squid to handle both our port 80 and 443 traffic, we have the issue that we can use redirects at the webserver level to redirect certain pages to https:// . So this is handled in Squid. First, make a simple script.  There&#8217;s a possibility another redirector like Squirm might do a better job, [...]]]></description>
			<content:encoded><![CDATA[<p>In configuring Squid to handle both our port 80 and 443 traffic, we have the issue that we can use redirects at the webserver level to redirect certain pages to https:// .</p>
<p>So this is handled in Squid.</p>
<p>First, make a simple script.  There&#8217;s a possibility another redirector like Squirm might do a better job, but I haven&#8217;t played with them.</p>
<blockquote><p>!/usr/bin/perl<br />
$|=1;<br />
while (&lt;&gt;) {<br />
s@http://www7.getmiro.(com|net|org)/adopt(.*)$@301:https://www7.getmiro.com/adopt$2@;<br />
print;<br />
}</p></blockquote>
<p>Saved at /etc/squid3/squid_redirector.pl and chown/chmod so the user &#8220;proxy&#8221; that squid runs under can run it.  Your path, of course, may vary.</p>
<p>The key part for what we need is that we pre-pend &#8220;301&#8243; before https:  in the rewrite.  When this is returned to the user&#8217;s browser it redirects them to the secure page.  This script also takes anything at com, net, or org and forces them to a tld of .com as well.</p>
<p>It&#8217;s easy to test this perl script.  Simply type ./squid_redirector.pl which launches it interactively.</p>
<blockquote><p><span style="color: #000000;"># ./squid_redirector.pl<br />
</span><span style="color: #ff0000;"><span style="color: #000000;">http://www7.getmiro.com/foo</span></p>
<p>http://www7.getmiro.com/foo</p>
<p><span style="color: #000000;">http://www7.getmiro.com/adopt/test</span><br />
301:https://www7.getmiro.com/adopt/test<br />
<span style="color: #000000;">http://www7.getmiro.<strong>net</strong>/adopt/matt/is/an/evil/genius </span><br />
301:https://www7.getmiro.<strong>com</strong>/adopt/matt/is/an/evil/genius</span></p></blockquote>
<p>Next, tell Squid to use it.  We need to enable these lines in the squid.conf file:</p>
<p style="padding-left: 30px;">url_rewrite_program /etc/squid3/squid_redirector.pl<br />
url_rewrite_children 10<br />
url_rewrite_host_header off<br />
url_rewrite_bypass on</p>
<p>The first line tells Squid what to use to rewrite URLs, the second tells it to spawn 10 instances on startup.  I&#8217;m not sure, in the end, if host_header needs to be off.  url_rewrite_bypass on allows Squid to skip the re-writing step if all the redirectors are busy.  That&#8217;s a decision knowing our security risks, users, and needs &#8212; and I&#8217;m going with more reliability over absolute security.  We&#8217;ll should see skips showing up in the logs and adjust settings from there if necessary.</p>
<p>Restart Squid, give it a test.  Famous last words &#8212; it should work now.</p>
<p>References:</p>
<p>http://wiki.squid-cache.org/Features/Redirectors</p>
<p>http://brainextender.blogspot.com/2009/01/simple-squid-redirector-perl-script.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.d90.us/toolbox/2009/05/29/squid-handling-http-https-redirects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

