Nginx with ASP.NET Page Methods
I recently spent some time moving an ASP.NET 4.0 website from Apache (mod_mono) over to Nginx with FastCGI to take advantage of Nginx’s killer performance and low memory footprint.
After following the FastCGI Nginx guide on the mono website I was mostly up and running. However, my app has some Page Methods I use for AJAX calls via jQuery and they were not working properly. I was getting 405 or 500 responses from Nginx when jQuery posted to the these methods. I came across this related article: lighttpd + Mono Asp.Net; albeit related to lighttpd it still deals with FastCGI issues. It shed light of the fact that mono’s fastcgi-mono-server is expecting parameters to be passed in a certain format from Nginx to properly handle Page Methods. The default fastcgi config for Nginx does not play nicely with ASP.NET Page Methods.
Then I came across this article: ASP.NET Ajax Error 405 on Nginx, which got me closer to the solution. Although I thought this would be my fix it didn’t work when I implemented the example config and actually caused a different server error. After some trial and error I found that the fastcgi_param PATH_TRANSLATED config line should not be included. I’m not sure why including it worked for the author of this article but perhaps he is using a different version of mono. For the record, I am using mono 2.10.8 with fastcgi-mono-server4 (i.e. .NET 4.0). In the end, the following config worked for me:
location ~\.aspx(.*) {
include fastcgi_params;
fastcgi_split_path_info ^(.+.aspx)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index Default.aspx;
fastcgi_pass 127.0.0.1:9000;
}
If you are using ASMX Page Methods you simply need to copy this config and change all the aspx references to asmx and it should work.




Dear Brady,
thanks for your post. I’m trying to setup Linux with Mono and Nginx in a Raspberry Pi and this is the solution of all my problem.
I don’t know why this configuration is not in the official guide on mono site…
Thanks a lot
Claudio
since you have used both mod_mono and Nginx. can i ask you, http://www.mono-project.com/ASP.NET#Limitations states that WebParts APIs is not implemented on mod-mono but no mantioning if these limitations are same on Ngix. (i googled for it didn’t find an aswer, thats how i found your site.). i don’t much (jet) about setting up an server, or how they work in general. what im trying to find out is: if a create a compiled controler like object in C++ and host it on a Nginx server using CTpp module and host a .NetMVC4 site on Nginx can i use the C++ object as part of my website?
Thanks a lot man!