This HowTo explain how to setup mono and nginx for hosting ASP.Net Page on ubuntu/Debain Box:

Install the required Packages:

apt-get install nginx  mono-runtime mono-gmcs libmono-system-data2.0-cil libmono-system-messaging2.0-cil libmono-system-ldap2.0-cil libmono-system-messaging2.0-cil libmono-system-runtime2.0-cil libmono-system-web2.0-cil libmono-system-web-mvc1.0-cil libmono-wcf3.0-cil libmono-winforms2.0-cil mono-fastcgi-server2 mono-fastcgi-server4

Verify the mono installation

mono –version

Setup start stop script for the mono:

vi /etc/init.d/mono

#!/bin/sh

### BEGIN INIT INFO
# Provides:          monoserve.sh
# Required-Start:    $local_fs $syslog $remote_fs
# Required-Stop:     $local_fs $syslog $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start fastcgi mono server with hosts
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mono
NAME=mono
DESC=mono

MONOSERVER=$(which fastcgi-mono-server4)
MONOSERVER_PID=$(ps auxf | grep fastcgi-mono-server4.exe | grep -v grep | awk ‘{print $2}’)

WEBAPPS=”/:/PATH/TO/APPLICATION/”

case “$1” in
start)
if [ -z “${MONOSERVER_PID}” ]; then
echo “starting mono server”
${MONOSERVER} /applications=${WEBAPPS} /socket=tcp:127.0.0.1:9000 &
echo “mono server started”
else
echo ${WEBAPPS}
echo “mono server is running”
fi
;;
stop)
if [ -n “${MONOSERVER_PID}” ]; then
kill ${MONOSERVER_PID}
echo “mono server stopped”
else
echo “mono server is not running”
fi
;;
esac

exit 0

chmod +x /etc/init.d/mono

/etc/init.d/mono start

/etc/init.d/mono stop

Setup Nginx virtual host

vi /etc/nginx/sites-available/default

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

location / {
root /var/www/mono.com/;
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;
}
}

vi /etc/nginx/sites-available/default-ssl

server {
listen       443;
server_name  gloss.io http://www.gloss.io;
ssl                  on;
ssl_certificate      /etc/ssl/certificate.crt;
ssl_certificate_key  /etc/ssl/server.key;
#access_log  /var/log/nginx/log/host.access.log  main;

location / {
root /var/www/mono/current/;
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;
}
}

ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

ln -s /etc/nginx/sites-available/default-ssl /etc/nginx/sites-enabled/default-ssl

Edit the fastcgi parameters

vi /etc/nginx/fastcgi_params

fastcgi_param  PATH_INFO          “”;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

Restart nginx

/etc/init.d/nginx restart

Test ASP pages:

mkdir /var/www/mono.com/
cd /var/www/mono.com/
vi index.aspx
<%=”hello, world!”%>

Advertisements