<?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>House of Metnetsky &#187; scgi</title>
	<atom:link href="http://cowarthill.com/blog/index.php/tag/scgi/feed/" rel="self" type="application/rss+xml" />
	<link>http://cowarthill.com/blog</link>
	<description>Run Tortoise Run</description>
	<lastBuildDate>Fri, 26 Feb 2010 17:15:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mono + SCGI</title>
		<link>http://cowarthill.com/blog/index.php/2009/06/10/mono-scgi/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/06/10/mono-scgi/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 21:46:13 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[scgi]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=267</guid>
		<description><![CDATA[Over a year ago I started a SCGI daemon for Mono (scgi-mono-server). For those who don&#8217;t know, the &#8220;SCGI protocol is a replacement for the Common Gateway Interface (CGI) protocol. It is a standard for applications to interface with HTTP servers. It is similar to FastCGI but is designed to be easier to implement&#8221;.I stopped [...]]]></description>
			<content:encoded><![CDATA[<div>Over a year ago I started a <a title="http://python.ca/scgi/protocol.txt" href="http://" target="_blank">SCGI</a> daemon for <a title="http://www.mono-project.com/" href="http://" target="_blank">Mono</a> (scgi-mono-server). For those who don&#8217;t know, the <a href="http://www.mems-exchange.org/software/scgi" target="_blank">&#8220;SCGI protocol is a replacement for the Common Gateway Interface (CGI) protocol. It is a standard for applications to interface with HTTP servers. It is similar to FastCGI but is designed to be easier to implement&#8221;</a>.I stopped all development shortly after I started because <a href="http://www.lighttpd.net/" target="_blank">lighttpd</a> (the web server I cared about) required a very small patch to be useful. Having supplied the <a href="http://redmine.lighttpd.net/projects/lighttpd/repository/revisions/2223/diff/branches/lighttpd-1.4.x/src/mod_scgi.c" target="_blank">patch</a> I waited around for it to be rolled into a release (<a href="http://www.lighttpd.net/2008/9/30/1-4-20-Otherwise-the-terrorists-win" target="_blank">1.4.20</a>) and then waited for it to be picked up by <a href="http://packages.ubuntu.com/search?keywords=lighttpd&amp;searchon=names&amp;suite=jaunty&amp;section=all" target="_blank">Ubuntu</a>, but it still hasn&#8217;t. So what brought it back to life? A silly bug: <a href="https://bugs.launchpad.net/ubuntu/+source/mod-mono/+bug/227781" target="_blank">https://bugs.launchpad.net/ubuntu/+source/mod-mono/+bug/227781</a>.</div>
<p>Some of our servers need both PHP5 &amp; Mono to run side-by-side so one of our guys listed the options:</p>
<div>
<ul>
<li dir="ltr">Pull mono &amp; <a href="http://www.mono-project.com/Mod_mono" target="_blank">mod-mono</a> 1.9.1 back-ports from a <a href="https://launchpad.net/ubuntu/+ppas" target="_blank">PPA</a> (<a href="http://ppa.launchpad.net/directhex/ppa/ubuntu">http://ppa.launchpad.net/directhex/ppa/ubuntu</a>)</li>
<li dir="ltr">Patch and rebuild <a href="http://www.mono-project.com/Mod_mono" target="_blank">mod-mono</a> 1.2.5 ourselves</li>
<li dir="ltr">Switch to <a href="http://en.wikipedia.org/wiki/FastCGI" target="_blank">FastCGI</a> for PHP5, so we can use apache2-mpm-worker for mod-mono-server</li>
<li dir="ltr">Switch from Apache to lighttpd (and rebuild with our patch)</li>
<li dir="ltr">Switch from Apache + mod-mono to Apache + FastCGI or SCGI (requires patching lighttpd)</li>
<li dir="ltr">Switch from Apache + mod-mono to Apache + mod_proxy for <a href="http://www.mono-project.com/ASP.NET#ASP.NET_hosting_with_XSP" target="_blank">XSP</a></li>
</ul>
<p>Given our growing dislike for Apache &amp; appreciation for lighttpd we decided on a phased approach:</p>
<ul>
<li dir="ltr">Switch PHP5 to Apache + <a href="http://en.wikipedia.org/wiki/FastCGI" target="_blank">FastCGI</a></li>
<li dir="ltr">Switch Mono to Apache + SCGI</li>
<li dir="ltr">Run for a while (make sure everything works well)</li>
<li dir="ltr">Switch from Apache to lighttpd</li>
</ul>
<p>We choose SCGI for Mono over <a href="http://en.wikipedia.org/wiki/FastCGI" target="_blank">FastCGI</a> because:</p>
<ul>
<li dir="ltr">FastCGI requires a lot of chatter between the client &amp; server</li>
<li dir="ltr">Great incentive to finally give the server to Mono</li>
</ul>
<p>With our approach in mind I started working on scgi-mono-server again, but with a new target &#8211; Apache. This shouldn&#8217;t have been very hard given that mod_scgi is provided by <strong>Quixote</strong>, but there were a few stumbling blocks. Apache, for whatever reason, has decided to break the SCGI specification (in my eyes).  As stated in the <strong>Protocol</strong>: &#8220;[t]he format of the response is not specified&#8221; &#8211; meaning whatever the SCGI server sends back to the client (Apache, lighttpd, etc) should go back to the originator (web browser). Apache however, does not honor this. </p>
<p>The first line of any HTTP response (AFAIK) should be it&#8217;s <em>Status Line</em>:</p>
<p><strong>HTTP/1.1 200 OK</strong>.</p>
<p>Apache&#8217;s mod_scgi requires that all lines until the body have a colon so that is can parse the header and update it&#8217;s internal data model. Therefore, our first line now has to be replaced by:</p>
<p><strong>Status: 200 OK</strong></p>
<p>Thankfully the <strong>Example</strong> section of the protocol showed me how to <strong><em>fix the issue</em></strong>. I&#8217;m tempted to patch Apache/mod_scgi but I&#8217;m a bit worried about how many SCGI servers require this broken code. So for now I&#8217;ve added a configuration option that can be put inside ASP.NET&#8217;s web.config to control the <strong><em>hack</em></strong>:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;appSettings&gt;
	&lt;add key=&quot;MonoServerApacheStatus&quot; value=&quot;true&quot; /&gt;
&lt;/appSettings&gt;
</pre>
<p>I&#8217;ll be submitting the server back to Mono with some documentation after it goes through some solid developer testing on our side &#8211; so I hope someone enjoys!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/06/10/mono-scgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

