FastCGI Nginx

Nginx (http://wiki.codemongers.com/) ("engine x") is a high-performance HTTP server and reverse proxy. Designed not just as a typical web server but also to proxy requests, proxying to FastCGI is second nature to Nginx and can be done in just a few short lines of configuration.

Table of Contents

1 Step 1: Setting Up the FastCGI Pass
2 Step 2: Adding Index Pages

3 Bada Bing!

NOTE

  1. OpenSuSE10.2 (http://en.opensuse.org/OpenSUSE_News/10.2-Release) (Nginx 0.5.30 from source)
  2. If you have tested an additional configuration,please email me at brian.nickel@gmail.com (mailto:brian.nickel@gmail.com).

Step 1: Setting Up the FastCGI Pass

Insert the following into the server section of conf/nginx.conf:

        location ~ \.(aspx|asmx|ashx|asax|ascx|soap|rem|axd|cs|config|dll)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        conf/fastcgi_params;
        }


  1. location ~ ... {} specifies theextensions to pass to the FastCGI server.
  2. fastcgi_pass ... specifies the serverand port of the Mono server. The server must be started manually with arguments like the below.
fastcgi-mono-server2 /socket=tcp:9000

The value can also be the path to a Unix socket, eg "unix:/tmp/fastcgi.socket". This corresponds to a Mono server started with the path below.


fastcgi-mono-server2 /socket=unix:/tmp/fastcgi.socket
  1. fastcgi_param SCRIPT_FILENAME ...specifies the physical location of the file on the machine running the Mono server. $fastcgi_script_name is the requested path, eg. "/default.aspx" or "/test/file.aspx" so it should be preceeded with the physical path of the document root. In the above example, the files are expected to be in the server's root directory.
  2. include ... includes configurationoptions from the default set of FastCGI parameters. When installing the test server, this file failed to copy so it may have to be copied manually from the source package.

Step 2: Adding Index Pages

Nginx includes a setting fastcgi_index ... for specifying an index page for the FastCGI pass. However, it is unclear to me how this works, for extension based passing and appears to only support one extension, so I'm recommending a different method. For more information on fastcgi_index, see the FastCGI documentation (http://wiki.codemongers.com/NginxHttpFcgiModule).

The method I recommend is editing the index page list in the server's default location. For instance, a standard server will have the the first block of code below, and you will want to update it to the second block of code.

BEFORE


        location / {
            root   html;
            index  index.html index.htm;
        }

AFTER


        location / {
            root   html;
            index  index.html index.htm index.aspx default.aspx;
        }


Bada Bing!

You should now have ASP.NET working with Nginx. Enjoy!