<?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>/root.eu &#187; apache</title>
	<atom:link href="http://slashroot.eu/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://slashroot.eu</link>
	<description>Notepad of geeky sysadmin</description>
	<lastBuildDate>Thu, 23 Jun 2011 13:04:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>HOWTO Massive virtual hosting on tomcat</title>
		<link>http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/</link>
		<comments>http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 07:33:54 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=148</guid>
		<description><![CDATA[<a href="http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/" title="HOWTO Massive virtual hosting on tomcat "></a>I found out today that tomcat virtual hosts are pretty lame. I thought that these all java based tomcat`s fancy plugins are much more powerful than old, simpleapache httpd. Well they aren`t. I wasn`t able to configure massive virtual hosting &#8230;<p class="read-more"><a href="http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/" title="HOWTO Massive virtual hosting on tomcat "></a><p>I found out today that tomcat virtual hosts are pretty lame. I thought that these all java based tomcat`s fancy plugins are much more powerful than old, <em>simple</em>apache httpd. Well they aren`t. I wasn`t able to configure massive virtual hosting for servlets. I wanted to run diffrent web application based on domain name that comes in URL. For example <code>myapp1.example.com</code> would run application <code>myapp1</code>, <code>myapp2.example.com</code> would run <code>myapp2</code>, etc. And there could be hundreds of them so I didn`t want to add hundreds of entries in <code>server.xml</code> config file. I`m a lazy person <img src='http://slashroot.eu/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>In order to configure virtual hosting based on above assumptions I used apache http server as a proxy to tomcat.<br />
First you need to add wildcard records to your domain (<code>example.com</code>) so that records of all its subdomains can be resolved to IP address of your server. Following record should be added to your bind server zone config:</p>
<pre>
*   IN   A   1.2.3.4
</pre>
<p>where <code>1.2.3.4</code> is IP address of your server.</p>
<p>Next you need to configure httpd server. Please make sure that you have ajp proxy module installed on your server, as connections to tomcat are based on AJP protocol. On CentOS/RHEL 5 this module is included in standard httpd package (see <code>/etc/httpd/conf.d/proxy_ajp.conf</code>).<br />
Now you need to create configuration for your virual hosts. I created a new file <code>/etc/httpd/conf.d/tomcat-vhosting.conf</code>:</p>
<pre>
UseCanonicalName Off
RewriteEngine On

# vhost map using perl script
RewriteMap vhost prg:/usr/local/bin/apache-getvhost.pl

# do no rewrite restricted names
RewriteCond %{SERVER_NAME} !^docs\.
RewriteCond %{SERVER_NAME} !^examples\.
RewriteCond %{SERVER_NAME} !^host-manager\.
RewriteCond %{SERVER_NAME} !^ROOT\.

# rewrite it
RewriteRule ^/(.*)$ ajp://localhost:8009/${vhost:%{SERVER_NAME}}/$1 [P]
</pre>
<p>Quite simple and cool, isn`t it? <img src='http://slashroot.eu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I`m sure that you probably expected <code>VirtualHost</code> directives, but all you need is a powerfull rewriting feature of apache. This configuration allows to access myapp application located in tomcat`s webapps directory via <code>http://myapp.example.com</code>.<br />
I used custom rewrite map which is a simple perl script. All it does is extract subdomain from server name based on URL.</p>
<p>Put the following in <code>/usr/local/bin/apache-getvhost.pl</code></p>
<pre>
#!/usr/bin/perl

$| = 1;

while (&lt;STDIN&gt;) {
  if (/(.*?)\.example\.com/)      {
      print $1."\n";
  } else {
      print $_."\n";
  }
}
</pre>
<p>and make it executable</p>
<pre>
chmod +x /usr/local/bin/apache-getvhost.pl
</pre>
<p>Now all you need to do is provide some applications to tomcat.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ujarzmione logi apache</title>
		<link>http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/</link>
		<comments>http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 10:35:03 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=68</guid>
		<description><![CDATA[<a href="http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/" title="Ujarzmione logi apache"></a>Na co dzień pracuję z aplikacją, która wyrzuca bardzo dużo &#8220;śmieci&#8221; do logów. Tym samym zapycha ona error log, który z nazwy powinien zawierać błędy, a nie informacje o niezainicjalizowanej zmiennej X. Postanowiłem ukrócić ten proceder i filtrować wychodzące z &#8230;<p class="read-more"><a href="http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/" title="Ujarzmione logi apache"></a><p>Na co dzień pracuję z aplikacją, która wyrzuca bardzo dużo &#8220;śmieci&#8221; do logów. Tym samym zapycha ona error log, który z nazwy powinien zawierać błędy, a nie informacje o niezainicjalizowanej zmiennej X. Postanowiłem ukrócić ten proceder i filtrować wychodzące z procesów apache`a komunikaty.</p>
<p>Wykorzystałem do tego perla, gdyż dość sprawnie radzi on sobie z obróbką tekstu i wyrażeniami regularnymi. Poniżej zawartość skryptu <strong>apache-logfilter.pl</strong></p>
<pre class="brush:perl">
#!/usr/bin/perl -w

use strict;

$|=1;   # use unbuffered output

my $logfile;

# check if logfile was passed as 1st argument
if ($ARGV[0])   {
$logfile=$ARGV[0];
}

# assign /dev/null as logfile unless it is already defined
$logfile="/dev/null" unless ($logfile);

# set umask
umask 0022;
my $loghandler=open(LOGFILE,'&gt;&gt;',$logfile);

# autoflush file handler
select((select(LOGFILE), $| = 1)[0]);

# inifinite loop over input from STDIN
while (&lt;STDIN&gt;) {

# omit unwanted lines matching the following patterns
next if (/^Use of uninitialized value/);
next if (/^"my" variable/);
next if (/^Subroutine \w+ redefined/);
next if (/^Variable ".*?" will not stay shared/);
next if (/^Odd number of elements in hash/);
next if (/^Argument ".*?" isn't numeric/);
next if (/^Useless use of .*? in void context/);
next if (/^substr outside of string at/);
next if (/^Unquoted string ".*?" may clash/);
next if (/^Scalar value @.*? better written as/);
next if (/^Parentheses missing around/);

# print to our logfile
print LOGFILE "$_";
}
</pre>
<p>Posiadając już taki skrypt należy przekazać w konfiguracji apache`a jego wywołanie. Odbywa się to za pomocą <em>pipe`a</em> przez który przekazywane są komunikaty do skrypty. W tym przypadku jako parametr podana jest ścieżka do właściwego pliku logu, do którego dopisywane są wiadomości (nie należy zapomnieć o właściwiej konfiguracji logrotate!).<br />
Przykładowa część konfiguracji:</p>
<p><code><br />
ErrorLog "|/usr/local/bin/apache-logfilter.pl /var/log/apache/error_log"<br />
</code></p>
<p>Ciekawą rzeczą jaką napotkałem tutaj był problem buforowanego wyjścia. Otóż do logu nie docierały żadne nowe wiadomości. Wielokrotnie sprawdzałem poprawność skryptu i za każdym razem działał on poprawnie zapuszczony z palca. Po krótkich poszukiwaniach znalazłem zmienną <strong>$|</strong>, której to niezerowe ustawienie powinno mój problem rozwiązać. A jednak nie rozwiązało. Dopiero wymuszenie tego na uchwycie otwartego pliku dało pożądane rezultaty. Odpowiada za to następujące wywołanie:</p>
<p><code><br />
select((select(LOGFILE), $| = 1)[0]);<br />
</code></p>
<p>Teraz wszystko śmiga jak należy &#8211;  czytelność logów zwiększyła się znacząco, a ich rozmiar zmniejszył się kilkukrotnie.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

