Running Mono ASP.NET and ASP.NET MVC web applications on Nginx

16 Dec 2009

Nginx web server installation (with root):

apt-get install nginx

Nginx configuration (as of version 0.7.63) is located in /etc/nginx/nginx.conf (which contains http configuration) and in /etc/nginx/sites-available/default (where is configuration of particular virtual host or hosts). In order to setup ASP.NET or ASP.NET MVC web application, you need to modify virtual host configuration.

server {
         listen   80;
         server_name  www.domain1.xyz;
         access_log   /var/log/nginx/your.domain1.xyz.access.log;

         location / {
                 root /var/www/www.domain1.xyz/;
                 index index.html index.htm default.aspx Default.aspx;
                 fastcgi_index Default.aspx;
                 fastcgi_pass 127.0.0.1:9000;
                 include /etc/nginx/fastcgi_params;
         }
}

ASP.NET and ASP.NET MVC web applications runs on Nginx through FastCGI protocol, therefore you need to add few lines into /etc/nginx/fastcgi_params.

fastcgi_param  PATH_INFO          "";
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

Now the Nginx part is complete, but to finish the whole thing Mono FastCGI server needs to be started.

fastcgi-mono-server2 /applications=www.domain1.xyz:/:/var/www/www.domain1.xyz/ /socket=tcp:127.0.0.1:9000

Now when Mono FastCGI server is up and running, Nginx configuration is complete and your application is in place (located in /var/www/www.domain1.xyz/) you can run the web server.

/etc/init.d/nginx start
blog comments powered by Disqus