xplicit / HyperFastCgi

Performant nginx to mono fastcgi server
MIT License
129 stars 49 forks source link
asp mono mono-server-fastcgi nginx web-server

Build Status

HyperFastCgi

HyperFastCgi hosts mono web applications with nginx. It's a primary replacement of mono-server-fastcgi for linux platform.

Key features:

Latest stable version https://github.com/xplicit/HyperFastCgi/tree/v0.3_stable

Installation

Prerequisites:

 sudo apt-get install autoconf automake libtool make libglib2.0-dev libevent-dev

For Debian 8 you additionally need to install libtool-bin package

Download the source and perform commands:

./autogen.sh --prefix=/usr
 make
 sudo make install

Installation on FreeBSD

Prerequisites:

 pkg install mono autoconf automake libtool gmake libevent2 pkgconf

If you want to use the buildin clang instead of gcc you can make a symlink to fool autoconf:

 ln -s /usr/bin/cc /usr/bin/gcc

Download the source and perform commands:

./autogen.sh --prefix=/usr/local
 gmake
 gmake install

Run

hyperfastcgi4 /config=<configfile> [arguments]

Arguments

Config file parameters

Samples of config files your can find in samples directory.

Configuration file is an XML config, which consists of four sections server listener apphost web-applications.

<configuration>
    <server>...General server settings is here...</server>
    <listener>... Address, port and related stuff here...</listener>
    <apphost>... Settings for application host...</apphost>
    <web-applications>
        <web-application>...Web App1 settings...</web-application>
        <web-application>...Web App2 settings...</web-application>
        ....
        <web-application>...Web AppN settings...</web-application>
    </web-applications>
</configuration>

Each section except of web-application has the attribute type which represents fully-qualified CLR type of the class, which will proceed the section. These types provide various behaviour described below and can be written by developer (see Developer section)

<server type="HyperFastCgi.ApplicationServers.SimpleApplicationServer">
    ..server parameters goes here..
</server>

All existing types are described in this manual.

<server> element

<listener> element

<listener> describes behaviour of how HyperFastCgi will listen and proceed incoming requests. Currently there are two listeners, which process FastCgi requests, but one can write it's own to process HTTP requests, for example.

<apphost> element.

<apphost> defines how requests in web application will be processed. HyperFastCgi has two apphosts: AspNet for running ASP.NET applications and Raw for directly working with HTTP request data.

<web-applications> element.

<web-applications> represents collection of <web-application> elements each of them defines web application will be hosted by the server.

<web-application> element.

Nginx configuration

See the wiki page for examples of how to configure Nginx

Writing RawHost Application

HyperFastCgi allows your to write fast web-request processing routines using C#. To do it you should do the following steps

  1. Create new C# library project and add HyperFastCgi as reference to the project.

  2. Create your own class derived from the class HyperFastCgi.AppHosts.Raw.BaseRawRequest.

  3. Override method Process and write here your own logic. See the sample

    public class HelloWorldRequest : BaseRawRequest
    {
        public override void Process(IWebResponse response)
        {
            Status = 200;
            StatusDescription = "OK";
            ResponseHeaders.Add("Content-Type","text/html; charset=utf-8");
            response.Send(Encoding.ASCII.GetBytes("Hello, World!"));
            response.CompleteResponse ();
        }
    }
  4. Get the samples/hello-world.config and replace <request-type> element value with the type name of your class. You should get something like this

    <request-type>YourNameSpace.HelloWorldRequest, YourAssemblyName</request-type> 
  5. You're possible have to place your assembly into the GAC or put it under bin folder of your web-application, otherwise web-server won't find it. If your web application is located under /var/www/yourapp you should place the assembly to /var/www/yourapp/bin

Package Build Recipe Using FPM-Cookery

Here is a fpm build recipe for HyperFastCgi

https://github.com/sepulworld/fpm-hyperfastcgi

Additional Info

For more information read the blog http://forcedtoadmin.blogspot.com