Mono + SCGI
Some of our servers need both PHP5 & Mono to run side-by-side so one of our guys listed the options:
- Pull mono & mod-mono 1.9.1 back-ports from a PPA (http://ppa.launchpad.net/directhex/ppa/ubuntu)
- Patch and rebuild mod-mono 1.2.5 ourselves
- Switch to FastCGI for PHP5, so we can use apache2-mpm-worker for mod-mono-server
- Switch from Apache to lighttpd (and rebuild with our patch)
- Switch from Apache + mod-mono to Apache + FastCGI or SCGI (requires patching lighttpd)
- Switch from Apache + mod-mono to Apache + mod_proxy for XSP
Given our growing dislike for Apache & appreciation for lighttpd we decided on a phased approach:
- Switch PHP5 to Apache + FastCGI
- Switch Mono to Apache + SCGI
- Run for a while (make sure everything works well)
- Switch from Apache to lighttpd
We choose SCGI for Mono over FastCGI because:
- FastCGI requires a lot of chatter between the client & server
- Great incentive to finally give the server to Mono
With our approach in mind I started working on scgi-mono-server again, but with a new target – Apache. This shouldn’t have been very hard given that mod_scgi is provided by Quixote, 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 Protocol: “[t]he format of the response is not specified” – 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.
The first line of any HTTP response (AFAIK) should be it’s Status Line:
HTTP/1.1 200 OK.
Apache’s mod_scgi requires that all lines until the body have a colon so that is can parse the header and update it’s internal data model. Therefore, our first line now has to be replaced by:
Status: 200 OK
Thankfully the Example section of the protocol showed me how to fix the issue. I’m tempted to patch Apache/mod_scgi but I’m a bit worried about how many SCGI servers require this broken code. So for now I’ve added a configuration option that can be put inside ASP.NET’s web.config to control the hack:
<appSettings> <add key="MonoServerApacheStatus" value="true" /> </appSettings>
I’ll be submitting the server back to Mono with some documentation after it goes through some solid developer testing on our side – so I hope someone enjoys!