Nginx – Deploying ASP.NET Web API using Mono and Nginx

asp.netmononginx

I've been trying to deploy my Web API for quite some time now without success.
No matter how I throw things around in my configurations (by recommendations from my Google searches) I still run into the same frustrating error:

System.Web.HttpException
at System.Web.StaticFileHandler.ProcessRequest (System.Web.HttpContext context) [0x00000] in <filename unknown>:0
at System.Web.DefaultHttpHandler.BeginProcessRequest (System.Web.HttpContext context, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0
at System.Web.HttpApplication+<Pipeline>c__Iterator1.MoveNext () [0x00000] in <filename unknown>:0
at System.Web.HttpApplication.Tick () [0x00000] in <filename unknown>:0

This shows as an Error 404 in my browser.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Details: Requested URL: /MyAPI/Home/Index

I should add that it runs fine when debugging with MonoDevelop using XSP4 which is why I believe this to be a configuration issue rather than a code issue.

My nginx configuration:

server {
    listen 80;
    root /var/www/MyAPI/;
    server_name MyAPI;

    location / {
        fastcgi_pass 127.0.0.1:9000;
        include /etc/nginx/fastcgi_params;
    }
}

I've tried both using a webapp-file and just typing it all into the command line.

<apps>
<web-application>
    <name>MyAPI</name>
    <vhost>*</vhost>
    <vport>80</vport>
    <vpath>/</vpath>
    <path>/var/www/MyAPI/</path>
</web-application>
</apps>

Then in the command line I've tried:

fastcgi-mono-server4 /applications=/MyAPI:/var/www/MyAPI/ socket=tcp:127.0.0.1:9000

And

fastcgi-mono-server4 --appconfigdir=/etc/webapps socket=tcp:127.0.0.1:9000

What am I missing here? Does anyone have a solution to this?

Best Answer

It turns out that the issue was caused by using the Precompile option when publishing the Web API. When I tried to publish the app without using Precompile everything ran smoothly.