Serving your ASP.NET MVC site on Nginx / fastcgi-mono-server4

In my previous post I showed you how to compile and install mono and get your MVC site up running using the development web server xsp4. The next step is to serve your site using a real web server, my choice is nginx.

First, we need a configuration file for the nginx site. If you haven’t already got nginx installed, install it (sudo apt-get install nginx).


server {
    listen   80;
    root  /home/peter/MonoMvcDeploy/;

    location / {
      root /home/peter/MonoMvcDeploy/;
      index index.html index.htm default.aspx Default.aspx;
      fastcgi_index /Home;
      include /etc/nginx/fastcgi_params;

Type “sudo service nginx reload” to reload the configuration. Browsing to the site should give you a fastcgi error since there is no fastcgi server listening on yet. So far this is a good thing and shows that your configuration is correct.

Next we create a start script for our fastcgi server.


source ./
fastcgi-mono-server4 /applications=/:/home/peter/MonoMvcDeploy/ /socket=tcp:

This is pretty straigt forward, the only thing that might be a bit confusing is this part “/:/home/peter/MonoMvcDeploy/”. This means that we want to map the URL / to the application in /home/peter/MonoMvcDeploy/. This allows us to run several applications in the same fastcgi server on different URLs.

Now try running the script and browse to your site, our sample MVC site should appear!

The last step is to create a upstart script to have our application start automatically at system boot


description "sionmailer web"
author      "peter"

start on startup
stop on shutdown


    echo $$ > /var/run/
    exec sudo -H -u peter /home/peter/startmvc 2>&1
end script

pre-start script
    echo "[`date`] (sys) Starting" >> /var/log/mvc.sys.log
end script

pre-stop script
    rm /var/run/
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/mvc.sys.log
end script

Save the config file and start the site: service mvc start.

All done, your site is being served by nginx/fastcgi-mono-server4!


3 thoughts on “Serving your ASP.NET MVC site on Nginx / fastcgi-mono-server4

  1. Hi.
    I’m getting Bad Gatewayt error when using fastcgi-mono-server4 and nginx? Site is working fine under xsp4.

Leave a Reply

Your email address will not be published. Required fields are marked *