Назад | Перейти на главную страницу

Mono 2.11 на nginx с использованием fastcgi-mono-server4 не будет работать

У меня установлен mono 2.11 с моим веб-сервером nginx 1.0.15, работающим на centos 6.2. Я собрал его из исходников, и xps2, xps4 и fastcgi-mono-server2 работают должным образом. Проблема в том, что я пытаюсь запустить fastcgi-mono-server4. Когда я бегу:

fastcgi-mono-server4 /applications=site:/:/srv/www/html/ /socket=tcp:127.0.0.1:9000 /loglevels=Debug /printlog=true

Вот что я получаю от fastcgi-mono-server2:

[2012-06-06 23:51:07Z] Debug   Record received. (Type: BeginRequest, ID: 1, Length: 8)
[2012-06-06 23:51:07Z] Debug   Record received. (Type: Params, ID: 1, Length: 801)
[2012-06-06 23:51:07Z] Debug   Record received. (Type: Params, ID: 1, Length: 0)
[2012-06-06 23:51:07Z] Debug   Read parameter. (QUERY_STRING = )
[2012-06-06 23:51:07Z] Debug   Read parameter. (REQUEST_METHOD = GET)
[2012-06-06 23:51:07Z] Debug   Read parameter. (CONTENT_TYPE = )
[2012-06-06 23:51:07Z] Debug   Read parameter. (CONTENT_LENGTH = )
[2012-06-06 23:51:07Z] Debug   Read parameter. (SCRIPT_NAME = /)
[2012-06-06 23:51:07Z] Debug   Read parameter. (REQUEST_URI = /)
[2012-06-06 23:51:07Z] Debug   Read parameter. (DOCUMENT_URI = /)
[2012-06-06 23:51:07Z] Debug   Read parameter. (DOCUMENT_ROOT = /srv/www/html)
[2012-06-06 23:51:07Z] Debug   Read parameter. (SERVER_PROTOCOL = HTTP/1.1)
[2012-06-06 23:51:07Z] Debug   Read parameter. (GATEWAY_INTERFACE = CGI/1.1)
[2012-06-06 23:51:07Z] Debug   Read parameter. (SERVER_SOFTWARE = nginx/1.0.15)
[2012-06-06 23:51:07Z] Debug   Read parameter. (REMOTE_ADDR = 192.168.128.121)
[2012-06-06 23:51:07Z] Debug   Read parameter. (REMOTE_PORT = 62326)
[2012-06-06 23:51:07Z] Debug   Read parameter. (SERVER_ADDR = 192.168.128.125)
[2012-06-06 23:51:07Z] Debug   Read parameter. (SERVER_PORT = 80)
[2012-06-06 23:51:07Z] Debug   Read parameter. (SERVER_NAME = site)
[2012-06-06 23:51:07Z] Debug   Read parameter. (REDIRECT_STATUS = 200)
[2012-06-06 23:51:07Z] Debug   Read parameter. (PATH_INFO = )
[2012-06-06 23:51:07Z] Debug   Read parameter. (SCRIPT_FILENAME = /srv/www/html/)
[2012-06-06 23:51:07Z] Debug   Read parameter. (HTTP_HOST = site)
[2012-06-06 23:51:07Z] Debug   Read parameter. (HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0)
[2012-06-06 23:51:07Z] Debug   Read parameter. (HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8)
[2012-06-06 23:51:07Z] Debug   Read parameter. (HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5)
[2012-06-06 23:51:07Z] Debug   Read parameter. (HTTP_ACCEPT_ENCODING = gzip, deflate)
[2012-06-06 23:51:07Z] Debug   Read parameter. (HTTP_CONNECTION = keep-alive)
[2012-06-06 23:51:07Z] Debug   Read parameter. (HTTP_COOKIE = ASP.NET_SessionId=0176BE8FC161E702439D3C91)
[2012-06-06 23:51:07Z] Debug   Record received. (Type: StandardInput, ID: 1, Length: 0)
[2012-06-06 23:51:08Z] Debug   Record sent. (Type: StandardOutput, ID: 1, Length: 196)
[2012-06-06 23:51:08Z] Debug   Record sent. (Type: StandardOutput, ID: 1, Length: 128)
[2012-06-06 23:51:08Z] Debug   Record sent. (Type: StandardOutput, ID: 1, Length: 0)
[2012-06-06 23:51:08Z] Debug   Record sent. (Type: EndRequest, ID: 1, Length: 8)

И вот что я получаю от fastcgi-mono-server4:

[2012-06-06 23:50:52Z] Debug   Record received. (Type: BeginRequest, ID: 1, Length: 8)
[2012-06-06 23:50:52Z] Debug   Record received. (Type: Params, ID: 1, Length: 801)
[2012-06-06 23:50:52Z] Debug   Record received. (Type: Params, ID: 1, Length: 0)
[2012-06-06 23:50:52Z] Debug   Read parameter. (QUERY_STRING = )
[2012-06-06 23:50:52Z] Debug   Read parameter. (REQUEST_METHOD = GET)
[2012-06-06 23:50:52Z] Debug   Read parameter. (CONTENT_TYPE = )
[2012-06-06 23:50:52Z] Debug   Read parameter. (CONTENT_LENGTH = )
[2012-06-06 23:50:52Z] Debug   Read parameter. (SCRIPT_NAME = /)
[2012-06-06 23:50:52Z] Debug   Read parameter. (REQUEST_URI = /)
[2012-06-06 23:50:52Z] Debug   Read parameter. (DOCUMENT_URI = /)
[2012-06-06 23:50:52Z] Debug   Read parameter. (DOCUMENT_ROOT = /srv/www/html)
[2012-06-06 23:50:52Z] Debug   Read parameter. (SERVER_PROTOCOL = HTTP/1.1)
[2012-06-06 23:50:52Z] Debug   Read parameter. (GATEWAY_INTERFACE = CGI/1.1)
[2012-06-06 23:50:52Z] Debug   Read parameter. (SERVER_SOFTWARE = nginx/1.0.15)
[2012-06-06 23:50:52Z] Debug   Read parameter. (REMOTE_ADDR = 192.168.128.121)
[2012-06-06 23:50:52Z] Debug   Read parameter. (REMOTE_PORT = 62326)
[2012-06-06 23:50:52Z] Debug   Read parameter. (SERVER_ADDR = 192.168.128.125)
[2012-06-06 23:50:52Z] Debug   Read parameter. (SERVER_PORT = 80)
[2012-06-06 23:50:52Z] Debug   Read parameter. (SERVER_NAME = site)
[2012-06-06 23:50:52Z] Debug   Read parameter. (REDIRECT_STATUS = 200)
[2012-06-06 23:50:52Z] Debug   Read parameter. (PATH_INFO = )
[2012-06-06 23:50:52Z] Debug   Read parameter. (SCRIPT_FILENAME = /srv/www/html/)
[2012-06-06 23:50:52Z] Debug   Read parameter. (HTTP_HOST = site)
[2012-06-06 23:50:52Z] Debug   Read parameter. (HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0)
[2012-06-06 23:50:52Z] Debug   Read parameter. (HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8)
[2012-06-06 23:50:52Z] Debug   Read parameter. (HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5)
[2012-06-06 23:50:52Z] Debug   Read parameter. (HTTP_ACCEPT_ENCODING = gzip, deflate)
[2012-06-06 23:50:52Z] Debug   Read parameter. (HTTP_CONNECTION = keep-alive)
[2012-06-06 23:50:52Z] Debug   Read parameter. (HTTP_COOKIE = ASP.NET_SessionId=0176BE8FC161E702439D3C91)
[2012-06-06 23:50:53Z] Debug   Record received. (Type: StandardInput, ID: 1, Length: 0)
[2012-06-06 23:50:53Z] Debug   Record sent. (Type: EndRequest, ID: 1, Length: 8)

Я не вижу, что делаю неправильно. Любая помощь была бы замечательной.

РЕДАКТИРОВАТЬ: Переделал вещи, и теперь я получаю ошибку 502 для плохого шлюза. Журналы по-прежнему выглядят так же.

Посмотрел в моем журнале ошибок для Nginx и нашел много таких записей:

2012/06/18 13:56:01 [error] 3108#0: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.128.121, server: site, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "site"

Я получаю один и тот же ответ независимо от того, включен fastcgi-mono-server4 или нет. Теперь он всегда показывает ошибку 502.

Мое примерное приложение MVC3 отлично работает на Mono 2.10.8.1 с сайта badgerports.org (я использую ubuntu).

После установки Mono 2.11.2 из исходного кода одно и то же приложение всегда будет возвращать 502 Bad Gateway, как и в вашем случае.

Мои логи nginx выглядели так:

[error] 3384#0: *101 upstream sent unexpected FastCGI record: 3 while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:8000"

После вызова fastcgi-mono-server4 с параметром printlog, установленным в значение true

sudo /opt/mono-2.11.2/bin/fastcgi-mono-server4 /printlog=True /applications=/:/var/www/mono/Mvc3Template /socket=tcp:127.0.0.1:9000

Он сгенерирует эту трассировку стека после посещения localhost: 8000 /

[2012-07-27 14:55:57Z] Notice  Beginning to receive records on connection.
[2012-07-27 14:55:58Z] Error   ERROR PROCESSING REQUEST: System.TypeInitializationException: An exception was thrown by the type initializer for Mono.WebServer.FastCgi.WorkerRequest

Server stack trace: 
  at Mono.WebServer.FastCgi.ApplicationHost.ProcessRequest (Mono.WebServer.FastCgi.Responder responder) [0x00001] in /home/r522/Desktop/mono-2.11.2/build/xsp-2.10.2/src/Mono.WebServer.FastCgi/ApplicationHost.cs:47 
  at (wrapper remoting-invoke-with-check) Mono.WebServer.FastCgi.ApplicationHost:ProcessRequest (Mono.WebServer.FastCgi.Responder)
  at (wrapper xdomain-dispatch) Mono.WebServer.FastCgi.ApplicationHost:ProcessRequest (object,byte[]&,byte[]&)

Exception rethrown at [0]: 
 ---> System.InvalidCastException: Cannot cast from source type to destination type.
  at System.Configuration.ConfigurationManager.get_AppSettings () [0x00000] in <filename unknown>:0 
  at Mono.WebServer.FastCgi.WorkerRequest..cctor () [0x0002c] in /home/r522/Desktop/mono-2.11.2/build/xsp-2.10.2/src/Mono.WebServer.FastCgi/WorkerRequest.cs:50 
  --- End of inner exception stack trace ---
  at (wrapper xdomain-invoke) Mono.WebServer.FastCgi.ApplicationHost:ProcessRequest (Mono.WebServer.FastCgi.Responder)
  at (wrapper remoting-invoke-with-check) Mono.WebServer.FastCgi.ApplicationHost:ProcessRequest (Mono.WebServer.FastCgi.Responder)
  at Mono.WebServer.FastCgi.Responder.Process () [0x00060] in /home/r522/Desktop/mono-2.11.2/build/xsp-2.10.2/src/Mono.WebServer.FastCgi/Responder.cs:90 
[2012-07-27 14:55:58Z] Notice  Finished receiving records on connection

Вот некоторые из моих конфигураций:

#/etc/nginx/sites-enabled/mono

 server {
         listen   8000;
         server_name  localhost;
         access_log   /var/log/nginx/mono.access.log;
         error_log    /var/log/nginx/mono.error.log;
         location / {
                 root /var/www/mono/Mvc3Template;
                 index index.html index.htm default.aspx Default.aspx;
                 fastcgi_index /Home/Index; # Points to HomeController Index Action
                 fastcgi_pass 127.0.0.1:9000;
                 include /etc/nginx/fastcgi_params;
         }
 }

-

# Directory structure
/var/www/mono
├── Mvc3Template
│   ├── bin
│   ├── Content
│   ├── Controllers
|   ... omitted rest
├── Mvc3Template.sln
├── Mvc3Template.suo
├── Mvc3Template.userprefs
├── packages

-

Я нашел решение своей проблемы здесь: bugzilla.xamarin.com/show_bug.cgi?id=2876 (Что меня беспокоит, так это то, что он предположительно был исправлен в феврале 2012 года - скомпилированный мной моно был выпущен в июне, но не работать из коробки)

Я сделал сценарий на основе найденных там предложений, который исправляет моно-установку, просто укажите переменную PREFIX в своем моно-каталоге и запустите его:

#!/bin/bash

# Your mono directory
PREFIX=/opt/mono-2.11.2


FILES=('mod-mono-server4'
       'fastcgi-mono-server4'
       'xsp4')

cd $PREFIX/lib/mono/4.0

for file in "${FILES[@]}"
do
   cp "$file.exe" ../4.5
done


cd $PREFIX/bin

for file in "${FILES[@]}"
do
  sed -ie 's|mono/4.0|mono/4.5|g' $file
done

После этого приложение "работает", но еще не совсем там. Это больше не 502, и я получаю хорошую трассировку стека ...

System.Web.Compilation.CompilationException
: at IKVM.Reflection.Reader.ModuleReader.ResolveType (Int32 metadataToken, IGenericContext context) [0x00000] in <filename unknown>:0

Description: Error compiling a resource required to service this request. Review your source file and modify it to fix this error.

Details: : at IKVM.Reflection.Reader.ModuleReader.ResolveType (Int32 metadataToken, IGenericContext context) [0x00000] in <filename unknown>:0

Error origin: Compiler

Error source file: ~/Global.asax
Exception stack trace:

Так что мне еще есть во что разобраться, но я надеюсь, что кое-что из этого будет вам полезно.