I have cloned the RazorRockstars project from https://github.com/ServiceStack/RazorRockstars.git and verified that it runs on Windows. Now I want to deploy it to Linux CentOS 6.3 with Mono 2.10.8. I followed this tutorial: http://pastebin.com/TBf3NWTw

The problem is that I can't get the solution to run the Razor views.

My mod_mono.conf file looks like this:

<IfModule !mod_mono.c>
  LoadModule mono_module /usr/lib/httpd/modules/mod_mono.so
</IfModule>

<IfModule mod_headers.c>
   Header set X-Powered-By "Mono"
</IfModule>

AddType application/x-asp-net .aspx
AddType application/x-asp-net .cshtml
AddType application/x-asp-net .asmx
AddType application/x-asp-net .ashx
AddType application/x-asp-net .asax
AddType application/x-asp-net .ascx
AddType application/x-asp-net .soap
AddType application/x-asp-net .rem
AddType application/x-asp-net .axd
AddType application/x-asp-net .cs
AddType application/x-asp-net .vb
AddType application/x-asp-net .master
AddType application/x-asp-net .sitemap
AddType application/x-asp-net .resources
AddType application/x-asp-net .skin  
AddType application/x-asp-net .browser
AddType application/x-asp-net .webinfo
AddType application/x-asp-net .resx
AddType application/x-asp-net .licx
AddType application/x-asp-net .csproj
AddType application/x-asp-net .vbproj
AddType application/x-asp-net .config
AddType application/x-asp-net .Config
AddType application/x-asp-net .dll
DirectoryIndex index.aspx
DirectoryIndex Default.aspx
DirectoryIndex default.cshtml
DirectoryIndex default.aspx
MonoServerPath "/opt/mono/bin/mod-mono-server4"

If I add a Default.aspx file to the /var/www/RazorRockstars folder I can view the main page on my screen, but if I click a link (Henrix) I end up with a error message message telling me "The requested URL /stars/dead/hendrix was not found on this server."

It's probably a simple solution to this. I have spent a couple of hours Googling for the answer without a solution.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top