Apache http://blog.samat.org/taxonomy/term/48/0 en Calculating bandwidth from a combined-format web server log http://blog.samat.org/2006/05/25/calculating-bandwidth-from-a-combined-format-web-server-log <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Given a combined web server access log, such as the ones generated by Apache, it can be useful to know the total amount of data transfer of all requests in that log. This task is simple: extract the field listing the number of bytes sent for a request, and add them all up. For something so simple, there is an odd lack of examples or pre-made scripts that do this. Or, at least, I couldn’t find&nbsp;any.</p> <p>I wrote my solution, calculate-data-transfer.py, in&nbsp;Python:</p> <p></div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-inline clearfix"><div class="field-label">Topic:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/tag/Python" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Python</a></div><div class="field-item odd"><a href="/tag/Apache" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Apache</a></div></div></div> Thu, 25 May 2006 09:03:21 +0000 Samat Jain 101 at http://blog.samat.org A better way to separate Apache log files by virtual host domains http://blog.samat.org/2006/05/23/a-better-way-to-separate-apache-log-files-by-virtual-host-domains <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Apache&#8217;s &#8220;combined&#8221; log format is one the most common log formats used in <a href="http://httpd.apache.org/docs/2.0/logs.html#accesslog">access logging</a>, containing useful fields such as referrer and user agent. Unfortunately, it does not contain a field listing the the virtual host for whom a request was formed. With Apache, this is easily rectified by defining a custom logging format and post-processing logs to maintain compatibility. </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-inline clearfix"><div class="field-label">Topic:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/tag/Python" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Python</a></div><div class="field-item odd"><a href="/tag/Apache" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Apache</a></div></div></div> Tue, 23 May 2006 08:02:00 +0000 Samat Jain 99 at http://blog.samat.org A quick domain HTTP permanent redirect script for Apache/PHP http://blog.samat.org/2006/03/16/quick-domain-http-permanent-redirect-script-for-apache-php <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p><a href="/weblog/2006/02/27/changing-domains-again--welcome-to-samat-org">I mentioned earlier</a> that to get my old domains, tamasrepus.hotnudiegirls.com and tamasrepus.rhombic.net delisted from search engines, I was going to write a redirection script that would send an <span class="caps">HTTP</span> status 301 (permanent redirect) to anything that tries to access those domains. It would send them to this current domain&nbsp;(samat.org).</p> <p>And I did. So, behold the script (save as&nbsp;index.php):</p> <p><code type="php"> <? $headers = array(); $headers[] = "HTTP/1.1 301 Moved Permanently"; $headers[] = "Location: http://samat.org" . $_SERVER['REQUEST_URI']; foreach($headers as $header) { header($header); } ?> </code></p> <p>Simple enough. More is needed, though: the web server needs to be told to use this script for all URLs. You can do this easily with Apache and the ErrorDocument&nbsp;directive:</p> <p><code> <VirtualHost 72.36.165.250:80> ServerName tamasrepus.hotnudiegirls.com DocumentRoot "/path/to/directory/containing/script" ErrorDocument 404 /index.php </VirtualHost> </code></p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-inline clearfix"><div class="field-label">Topic:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/tag/PHP" typeof="skos:Concept" property="rdfs:label skos:prefLabel">PHP</a></div><div class="field-item odd"><a href="/tag/Apache" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Apache</a></div></div></div> Thu, 16 Mar 2006 09:14:07 +0000 Samat Jain 79 at http://blog.samat.org Trying to emulate mod_gunzip with Apache 2 Filters http://blog.samat.org/2005/10/06/trying_to_emulate_mod_gunzip_with_apache_2_filters <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>The situation: I have gzipped content stored on an <a href="http://httpd.apache.org/">Apache 2 web server</a>. Specifically, <span class="caps">HTML</span> files&#8211;they are stored in this manner to save disk space. For clients that can handle on-the-fly decompression of such files, I want the files to be sent verbatim; for clients that cannot, I want the content decompressed and sent to these&nbsp;clients.</p> <p><a href="http://oldach.net/">mod_gunzip</a> by Helge Oldach is an Apache 1 module made for dealing with stored gzip files. It can negotiate with a client what kind of encoding it can accept, and send the appropriate compressed or non-compressed version. Unfortunetely, at this time, this module is only available for Apache&nbsp;1.</p> <p>Helge Oldach notes that it should be possible to create the equivalent mod_gunzip functionality using only Apache 2 filters. To an extent, yes. I&#8217;ve done&nbsp;so:</p> <p><code> ExtFilterDefine gunzip mode=output&nbsp;cmd="/bin/gunzip"</p> <p><Files *.gz> SetOutputFilter gunzip </Files> </code></p> <p>This won&#8217;t do the sophisticated (well, at least more sophisticated than the Apache 2 runtime configuration directives will allow) negotiation that mod_gunzip can do, watching for certain clients and combinations of&nbsp;headers.</p> <p>So, I&#8217;m stuck. I&#8217;ve a project I had been working on for school that involves <span class="caps">HTML</span> reports, collectively, that can be as large as 1.3 <span class="caps">GB</span>. Compressing each file with gzip decreases the collective size down to 300 <span class="caps">MB</span>, while still allowing the files to be viewed in most modern web browsers (apparently, at the time of this writing, this does <span class="caps">NOT</span> include Apple&#8217;s Safari (which happens to be used by several of my professors), though Konqueror/<span class="caps">KHTML</span> works&nbsp;fine).</p> <p>Note to self: port mod_gunzip to Apache 2. </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-inline clearfix"><div class="field-label">Topic:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/tag/Linux" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Linux</a></div><div class="field-item odd"><a href="/tag/Software" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Software</a></div><div class="field-item even"><a href="/tag/Apache" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Apache</a></div></div></div> Thu, 06 Oct 2005 16:31:00 +0000 Samat Jain 61 at http://blog.samat.org