Mono 2.11 with nginx or apache

2019-03-30 01:26发布

问题:

I have installed parallel Mono (2.11.3) following these instructions: http://www.integratedwebsystems.com/2012/04/install-mono-2-11/ Now I want to run my ASP.NET site on this Mono instance. I have created an empty MVC 4 site using the "Internet site" template in VS 2010 and published it to the Linux box running Mono.

I have succeeded in running it via xsp4 following these instructions ( http://www.integratedwebsystems.com/2011/06/get-mvc3-razor-running-on-mono/) to set up the environment variables prior to running xsp4. It works without major problems (I see that some new features, like CSS bundling, do not work, but I will deal with it later).

Now, I would like to use the production server like apache or nginx. However, it seems almost impossible, and it seems that I'm not the only one with this problem. For example, using this simple nginx configuration

server
{
    listen 80;
    server_name mvctest.mono;

    access_log /var/www/mvctest/log/access.log;
    error_log /var/www/mvctest/log/error.log debug;

    location /
    {
             root /var/www/mvctest/;
             index index.html index.htm default.aspx Default.aspx;
             fastcgi_index /Home;
             fastcgi_pass 127.0.0.1:9000;
             include /etc/nginx/fastcgi_params;
    }
}

results in 502 Bad Gateway error, and the log file says "upstream sent unexpected FastCGI record: 3 while reading response header from upstream". As for the Apache + mod_mono_server4, I have not moved past the error

Exception caught during reading the configuration file:
System.MissingMethodException: Method not found:     'System.Configuration.IConfigurationSectionHandler.Create'.
at     System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in <filename unknown>:0 
at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0 
at System.Configuration.ConfigurationManager.get_AppSettings () [0x00000] in <filename unknown>:0 
at Mono.WebServer.Apache.Server.get_AppSettings () [0x00001] in /opt/mono-2.11/build/xsp-2.10.2/src/Mono.WebServer.Apache/main.cs:208 
at Mono.WebServer.Apache.Server+ApplicationSettings..ctor () [0x0002a] in /opt/mono-2.11/build/xsp-2.10.2/src/Mono.WebServer.Apache/main.cs:63 

There are a lot of posts on this topic, even here on the Stackoverflow, but no real answers. However, some users do report that they succeeded in running MVC4 sites on mono with these servers, so I was wondering if anybody would like to share their configuration settings or step-by-step instructions?

回答1:

The install package is placing some files in the wrong place. For Apache, you'll have to move the file mod-mono-server4.exe from /usr/lib/mono/4.0 to /usr/lib/mono/4.5 and update the reference inside the file /usr/bin/mod-mono-server4.

If you were using XSP or FastCgi, the same treatment would be required for xsp4.exe and fastcgi-mono-server4.exe and their respective references in /usr/bin.

(I am starting to regret I followed down this Mono path... )



回答2:

Here's a script that solved my Mono 3.0.3/MVC 3/Nginx issues. After copying over the needed files, the site pulled up fine.



回答3:

You need to know which port mono server is listen to, and set fastcgi_pass to it in your Nginx configuration file.



回答4:

I'm not an expert in this matter but the following nginx configuration works for me in a slightly different configuration (nginx + mono 2.10 + F# + websharper):

server {
    listen   80;
    access_log   /var/log/myapp/access.log;

    location / {
            root /opt/myapp;
            index index.html index.htm default.aspx Default.aspx;
            fastcgi_pass unix:/var/run/myapp/fastcgisocket;
            include /etc/nginx/fastcgi_params;
    }
}

Of course, the fastcgi-mono-server will have to be configured to use the socket /var/run/myapp/fastcgisocket.

Note that you will have to be careful with the r/w permissions for this socket.

I still have the problem that nginx doesn't send multiple requests to be handled in parallel to the fastcgi-mono-server but besides this it works nice.

I hope it helps.