<?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>Jabbering Giraffe &#187; apache</title>
	<atom:link href="http://happygiraffe.net/blog/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Wed, 19 Oct 2011 10:40:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>mod_perl 1 blows chunks</title>
		<link>http://happygiraffe.net/blog/2008/10/07/mod_perl-1-blows-chunks/</link>
		<comments>http://happygiraffe.net/blog/2008/10/07/mod_perl-1-blows-chunks/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 11:37:56 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_perl]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1398</guid>
		<description><![CDATA[At $WORK, I&#8217;m looking at a web service built on mod_perl 1 / Apache 1. The service takes XML as input and returns XML as output. So far, so good. Unfortunately, whilst I was testing with curl, I found something &#8230; <a href="http://happygiraffe.net/blog/2008/10/07/mod_perl-1-blows-chunks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>At $WORK, I&#8217;m looking at a web service built on <a href="http://perl.apache.org/docs/1.0/index.html">mod_perl 1</a> / <a href="http://httpd.apache.org/docs/1.3/">Apache</a> 1.  The service takes XML as input and returns XML as output.  So far, so good.</p>
<p>Unfortunately, whilst I was testing with <a href="http://curl.haxx.se/">curl</a>, I found something odd:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  curl <span style="color: #660033;">-s</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-T-</span> <span style="color: #660033;">-H</span><span style="color: #ff0000;">'Content-Type: text/xml;charset=UTF-8'</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost<span style="color: #000000; font-weight: bold;">/</span>api <span style="color: #000000; font-weight: bold;">&lt;</span> input.xml</pre></div></div>

<p>That <code>-T-</code> says to do a PUT request from stdin.  It fails and my code returned &#8220;no input&#8221;.</p>
<p>But when I did this, things worked:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  curl <span style="color: #660033;">-s</span> <span style="color: #660033;">-v</span> -Tinput.xml <span style="color: #660033;">-H</span><span style="color: #ff0000;">'Content-Type: text/xml;charset=UTF-8'</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost<span style="color: #000000; font-weight: bold;">/</span>api</pre></div></div>

<p>That reads directly from the file.  The only difference between the two requests is that the latter includes a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13">Content-Length</a> header whilst the former has <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41">Transfer-Encoding: chunked</a> instead.</p>
<p>This is the code that was reading the request.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$content</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header_in</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'Content-Type'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">read</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$content</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header_in</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'Content-Length'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">return</span> <span style="color: #0000ff;">$content</span><span style="color: #339933;">;</span></pre></div></div>

<p>So, if there&#8217;s no Content-Length, what should we do?  My first stop is always the venerable <a href="http://oreilly.com/catalog/9781565925670/">eagle book</a>.  There&#8217;s a little footnote next to <a href="http://www.modperl.com/book/chapters/ch9.html#item_read">read()</a>:</p>
<blockquote cite="http://www.modperl.com/book/chapters/ch9.html#item_read">
<p>At the time of this writing, HTTP/1.1 requests which do not have a Content-Length header, such as one that uses chunked encoding, are not properly handled by this API.</p>
</blockquote>
<p>Marvellous.  Now, I had a look around in <a href="http://search.cpan.org/src/GOZER/mod_perl-1.30/Apache/Apache.pm">the source code</a> and noticed a function called <code>new_read()</code>.  Unfortunately, that failed to work.  It stopped chunked reads, but failed to work for ordinary ones.</p>
<p>I did see <a href="http://markmail.org/message/agrmbuijzmmszjsi">a post</a> on the mod_perl mailing list which reckoned you could loop and read all input.  But I was unable to get that to work either.</p>
<p>So I just decided to disallow chunked input.  That&#8217;s fairly easy to do, and HTTP has a special status code for it: <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.12">411 Length Required</a>.  It&#8217;s not ideal, but unless this project gets upgraded to Apache 2 (unlikely, quite frankly), it seems to be the best option.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/10/07/mod_perl-1-blows-chunks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mod_security now switched off</title>
		<link>http://happygiraffe.net/blog/2006/12/02/mod_security-now-switched-off/</link>
		<comments>http://happygiraffe.net/blog/2006/12/02/mod_security-now-switched-off/#comments</comments>
		<pubDate>Sat, 02 Dec 2006 17:42:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/12/02/mod_security-now-switched-off/</guid>
		<description><![CDATA[Last night, I spent a long while trying to get mod_security working on this web server. Installation was simple, thanks to the FreeBSD ports system. Configuration was another matter entirely. Not having much experience of web application firewalls, I opted &#8230; <a href="http://happygiraffe.net/blog/2006/12/02/mod_security-now-switched-off/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last night, I spent a long while trying to get <a href="http://www.modsecurity.org/">mod_security</a> working on this web server.  Installation was simple, thanks to the FreeBSD ports system.  Configuration was another matter entirely.</p>
<p>Not having much experience of web application firewalls, I opted for the <a href="http://www.modsecurity.org/projects/rules/">ModSecurity Core Rules</a> to give me a head start.  These are essentially some pre-provided Apache configs that you can include into your existing config files.  It seems like a good idea, although some of the rules are questionable&#8212;I don&#8217;t really think that &#8220;googlebot visited&#8221; is a security event.</p>
<p>After configuring minor details like the audit log file, I deployed it.  Hmmm, front page still comes up, so let&#8217;s commit the configs to subversion.  <strong>Booom</strong>.</p>
<p>It turns out that the Core Rules don&#8217;t interact well with subversion in a number of minor, but irritating ways.  For example, they expect every request to come with an Accept header.  And only certain Content-Types can be submitted to the web server.  It&#8217;s all minor stuff, and relatively easy to work out how to fix.  This gave me a good feel for what&#8217;s involved in properly customizing mod_security.</p>
<p>This afternoon, I came back and inspected the logs.  There are nearly 400 events from mod_security.  Quite a lot of these were people trying to spam my <a href="http://happygiraffe.net/trac">trac instance</a> (which I&#8217;ve now finally gotten under control) and blog.  Importantly however, I noticed that it had blocked a legitimate user of an <span class="caps">RSS</span> feed.</p>
<p>At this point, I realised the problem.  mod_security needs a lot of work to set up and maintain.  You customize it towards a specific purpose&#8212;your application.  But I&#8217;m running lots of applications.  So it becomes harder and harder to customize correctly (particularly as I&#8217;m not running everything on it&#8217;s own virtualhost), because a rule that&#8217;s correct for subversion might well not be correct for trac.  Or more to the point, it&#8217;s going to take me a very long time to get it configured correctly.  So I&#8217;ve switched off mod_security for now.</p>
<p>Don&#8217;t take this as a slur on mod_security.  It&#8217;s a useful tool, and I will be using it again.  But it&#8217;s far easier to configure when you&#8217;re covering a single application running inside that Apache.  And you&#8217;ll still need to invest a good chunk of time to get it set up correctly (a very iterative process).</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/12/02/mod_security-now-switched-off/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mongrel&#039;s Default Charset</title>
		<link>http://happygiraffe.net/blog/2006/11/18/mongrels-default-charset/</link>
		<comments>http://happygiraffe.net/blog/2006/11/18/mongrels-default-charset/#comments</comments>
		<pubDate>Sat, 18 Nov 2006 18:07:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/11/18/mongrels-default-charset/</guid>
		<description><![CDATA[I suddenly noticed that my last entry had Unicode problems. How embarrassing. It turns out that mongrel doesn&#8217;t set a default charset, so the usual caveats apply. Looking through the mongrel docs, you can do something with the -m option, &#8230; <a href="http://happygiraffe.net/blog/2006/11/18/mongrels-default-charset/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I suddenly noticed that my <a href="http://happygiraffe.net/blog/archives/2006/11/14/java-is-free">last entry</a> had Unicode problems.  How <a href="http://happygiraffe.net/blog/archives/2006/09/16/unicode-for-rails">embarrassing</a>.  It turns out that <a href="http://mongrel.rubyforge.org/">mongrel</a> doesn&#8217;t set a default charset, so the usual <a href="http://tools.ietf.org/html/rfc2616#section-3.7.1" title="default to ISO-8859-1 [or more likely cp1252]">caveats</a> apply.  Looking through the mongrel docs, you can do something with the <code>-m</code> option, but it still seems difficult to apply a default universally.</p>
<p>Thankfully, I&#8217;m proxying to mongrel via Apache.  So correcting the situation turned out to be as simple as adding this to my VirtualHost config.</p>
<pre>
  AddDefaultCharset UTF-8
</pre>
<p>I was actually not sure that this would work, because Apache is proxying rather than serving files directly.  But it does work.  I suspect that it may not work un der Apache 1.3, but that would need to be confirmed.</p>
<p>But now the error is corrected and I&#8217;m Unicode happy once more.  Hurrah!</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/11/18/mongrels-default-charset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log Rotation</title>
		<link>http://happygiraffe.net/blog/2006/07/27/log-rotation/</link>
		<comments>http://happygiraffe.net/blog/2006/07/27/log-rotation/#comments</comments>
		<pubDate>Thu, 27 Jul 2006 00:22:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/07/27/log-rotation/</guid>
		<description><![CDATA[I hate log rotation. It&#8217;s a pain to configure on my FreeBSD server. Just look at newsyslog.conf. That, and my experiences of the utter non-portability of log rotation programs between different Unixes have led me to believe that programs should &#8230; <a href="http://happygiraffe.net/blog/2006/07/27/log-rotation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I hate log rotation.  It&#8217;s a pain to configure on my FreeBSD server.  Just look at <a href="http://www.freebsd.org/cgi/man.cgi?query=newsyslog.conf&#38;apropos=0&#38;sektion=5&#38;manpath=FreeBSD+6.1-RELEASE&#38;format=html" title="5">newsyslog.conf</a>.  That, and my experiences of the utter non-portability of log rotation programs between different Unixes have led me to believe that programs should probably handle their own log rotation.  It just makes life easier having one less thing to integrate with the Operating System.</p>
<p>So, I&#8217;ve switched my Apache over to using <a href="http://cronolog.org/">cronolog</a> in order to get date based logfiles automatically.  I&#8217;ve used it on a project at work recently and it really works a treat.</p>
<p>I also noticed that <a href="http://www.postgresql.org/">PostgreSQL</a> has grown the ability to <a href="http://www.postgresql.org/docs/8.1/static/runtime-config-logging.html">take care of its own log files</a> in recent versions.  So I&#8217;ve switched that to doing date based logging with automatic rotation as well.  Lovely.</p>
<p>All is not perfect of course.  Oh no, that would be far too simple.  There&#8217;s still the issue of removing old logfiles and/or compressing them.  But that seems to be a smaller integration problem.</p>
<p>Of course the trigger for all this activity was finding a 220Mb <code>access_log</code> lying around.  Doh!</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/07/27/log-rotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mod_perl 2 not ready yet</title>
		<link>http://happygiraffe.net/blog/2006/05/24/mod_perl-2-not-ready-yet/</link>
		<comments>http://happygiraffe.net/blog/2006/05/24/mod_perl-2-not-ready-yet/#comments</comments>
		<pubDate>Wed, 24 May 2006 11:52:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_perl]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/05/24/mod_perl-2-not-ready-yet/</guid>
		<description><![CDATA[I&#8217;ve spent nearly three days this week trying to port one of our sites to Apache 2.2 and mod_perl 2.0.2 (from Apache 1.3.33). It should be a relatively simple exercise thanks to the porting notes available: Upgrading to 2.2 from &#8230; <a href="http://happygiraffe.net/blog/2006/05/24/mod_perl-2-not-ready-yet/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent nearly three days this week trying to port one of our sites to Apache 2.2 and mod_perl 2.0.2 (from Apache 1.3.33).  It should be a relatively simple exercise thanks to the porting notes available:</p>
<ul>
<li><a href="http://httpd.apache.org/docs/2.2/upgrading.html">Upgrading to 2.2 from 2.0</a></li>
<li><a href="http://httpd.apache.org/docs/2.0/upgrading.html">Upgrading to 2.0 from 1.3</a></li>
<li><a href="http://perl.apache.org/docs/2.0/user/porting/compat.html">A Reference to mod_perl 1.0 to mod_perl 2.0 Migration.</a></li>
</ul>
<p>Yet sadly, there&#8217;s still a lot of problems with mod_perl 2.  Firstly, much <span class="caps">CPAN</span> software still hasn&#8217;t adjusted.  In my case it was <a href="http://search.cpan.org/dist/SOAP-Lite/"><span class="caps">SOAP</span>-Lite</a>.  But I also noticed that <a href="http://search.cpan.org/dist/libapreq/">libapreq</a> wasn&#8217;t classed as &#8220;ready&#8221; by Mason, so we had to fall back to <span class="caps">CGI</span>.pm there.</p>
<p>But the real killer is that they managed to completely break environment variables, in the name of thread safety.  Unfortunately, our application uses <a href="http://search.cpan.org/dist/Inline-Java/">Inline::Java</a> from inside Apache to talk to <a href="http://lucene.apache.org/java/docs/index.html">Lucene</a>.  Now Inline::Java spawns a <span class="caps">JVM</span> to run a <span class="caps">JAR</span> file and be the server.  So that the <span class="caps">JVM</span> can find the jar (as well as the lucene jar and our code), it sets <code>$ENV{CLASSPATH}</code>.  Except that change never shows up, so the <span class="caps">JVM</span> just says &#8220;unknown class&#8221; and exits.</p>
<p>Basically, mod_perl2 breaks <a href="http://perldoc.perl.org/functions/system.html">system</a>.  This is not clever.</p>
<p>So we won&#8217;t be upgrading to Apache 2.2 for a while.  This is a shame, as it has a bug fix we really need (&gt;4Gb file support).  Instead, we switched to using <span class="caps">FTP</span>.  Yuck.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/05/24/mod_perl-2-not-ready-yet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cygwin / Apache</title>
		<link>http://happygiraffe.net/blog/2006/03/01/cygwin-apache/</link>
		<comments>http://happygiraffe.net/blog/2006/03/01/cygwin-apache/#comments</comments>
		<pubDate>Wed, 01 Mar 2006 14:16:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cygwin]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/03/01/cygwin-apache/</guid>
		<description><![CDATA[A quick note about running Apache under cygwin. If you just run httpd2 on it&#8217;s own, you get an error about &#8220;invalid system call&#8221;. Very annoying. A quick bit of googling reveals that you have to have something called cygserver &#8230; <a href="http://happygiraffe.net/blog/2006/03/01/cygwin-apache/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A quick note about running Apache under cygwin.  If you just run <code>httpd2</code> on it&#8217;s own, you get an error about &#8220;invalid system call&#8221;.  Very annoying.</p>
<p>A quick bit of googling reveals that you have to have something called <code>cygserver</code> running.  You have to set it up by running <code>cygserver-config</code> the first time.  After that, you just need to ensure that <code>cygserver</code> is running.</p>
<p>Then, you can start Apache by saying <code>CYGWIN=server httpd2</code>.  And it all works!</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/03/01/cygwin-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

