We use Nginx/FastCGIMono to server mono ASP.NET sites ourselves, though there is nothing special you need to do with razor file extension mappings to handle razor files in the mod_mono config layer, all you need to do is ensure the request goes through to the ServiceStack ASP.NET host.
Configure it so the requests go through to ServiceStack
The goal should be just to ensure that the request goes through to ServiceStack to handle (ServiceStack will handle the rest once it gets to it), so you should avoid hindering it by specifying any middleware layer configs that may block it.
ServiceStack's Nginx + FastCGI Mono config for razor.servicestack.net
This is ServiceStack's nginx conf we use for hosting razor.servicestack.net with Nginx (on Ubuntu) which is located in a separate config file in /etc/nginx/sites-available/servicestack.net
:
server {
listen 0.0.0.0:80;
server_name razor.servicestack.net;
access_log /var/log/nginx/servicestack.net.log;
root /home/mythz/src/RazorRockstars/src/RazorRockstars.WebHost;
#get nginx to handle static files for better performance
location /img/ {
alias /home/mythz/src/RazorRockstars/src/RazorRockstars.WebHost/img/;
}
location ~* \.(ico|pdf|flv|swf|exe|html|htm|txt|css|js) {
add_header Cache-Control public;
add_header Cache-Control must-revalidate;
expires 1d;
}
#proxy all requests to monofastcgi backend + specify supported default documents
location / {
index index.html index.htm index.aspx default.htm Default.htm default.aspx Default.aspx Default.ashx default.cshtml;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
This is the Mono FastCGI config file we use to specify all the ASP.NET web applications we have which we keep in /etc/init.d/mono-fastcgi/ServiceStack.webapp
:
<apps>
<web-application>
<name>RazorRockstars</name>
<vhost>razor.servicestack.net</vhost>
<vport>80</vport>
<vpath>/</vpath>
<path>/home/mythz/src/RazorRockstars/src/RazorRockstars.WebHost</path>
</web-application>
...
<apps>
Finally this is the fastcgi command we run which is the process that hosts all the Mono ASP.NET sites as specified in the ServiceStack.webapp
above:
/usr/bin/fastcgi-mono-server4 --appconfigdir /etc/init.d/mono-fastcgi \
/socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log
The --appconfigdir /etc/init.d/mono-fastcgi
directive says to host all the ASP.NET web apps contained in any *.webapp
FastCGI Mono config files in the /etc/init.d/mono-fastcgi
directory.
What's happening under the hood
When a request to razor.servicestack.net
comes through to port 80 it gets handled by nginx, which matches the first nginx config block on server_name razor.servicestack.net;
.
The location / { .. }
directive tells nginx to forward all fallback routes to a fastcgi backed on port 9000 specified with fastcgi_pass 127.0.0.1:9000;
.
The request is now handled by FastCGI Mono which it directs to the ASP.NET web application identified with <vhost>razor.servicestack.net</vhost>
which as the ServiceStack handler is mounted at the / root path, ServiceStack ends up handling the request.