【问题标题】:nginx bad gateway 502 with mono fastcgi带有单声道fastcgi的nginx坏网关502
【发布时间】:2012-08-15 00:59:27
【问题描述】:

您好,所以我一直在尝试让我的网站在单声道(在 ubuntu 服务器上)上运行,并且我几乎一直关注 these tutorials

但是,当我的目录不是空白时,fastcgi 日志会显示:

    Notice  Beginning to receive records on connection.
    Error   Failed to process connection. Reason: Exception has been thrown by the target of an invocation.

我不太确定这意味着什么,根据我的操作,我可能会遇到另一个错误,告诉我找不到资源:

找不到资源。

    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.

请求的 URL:/Default.aspx/ 版本信息:Mono 运行时版本:2.10.8(tarball Thu Aug 16 23:46:03 UTC 2012)ASP.NET 版本:4.0.30319.1

如果我应该提供更多信息,请告诉我。

编辑:

我现在收到一个 nginx 网关错误。

我的 nginx 配置文件是这样的:

server {
    listen   2194;
    server_name localhost;
    access_log $HOME/WWW/nginx.log;

    location / {
      root $HOME/WWW/dev/;
      index index.html index.html default.aspx Default.aspx Index.cshtml;
      fastcgi_index Views/Home/; 
      fastcgi_pass 127.0.0.1:8000;
      include /etc/nginx/fastcgi_params;
    }
}

使用 xsp4 运行整个过程,我发现了“调用目标引发了异常”。

处理异常类型 TargetInvocationException 消息是异常 已被调用的目标抛出。 IsTerminating 已设置 到 True System.Reflection.TargetInvocationException: 异常有 被调用的目标抛出。

服务器堆栈跟踪:位于 System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr,
System.Reflection.Binder 绑定器,System.Object[] 参数,
System.Globalization.CultureInfo 文化)[0x00000] in :0 在 System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] 参数) [0x00000] in :0
在 System.Runtime.Serialization.ObjectRecord.LoadData (System.Runtime.Serialization.ObjectManager 管理器, ISurrogateSelector 选择器,StreamingContext 上下文)[0x00000] in :0 在 System.Runtime.Serialization.ObjectManager.DoFixups () [0x00000] 在 :0 在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader 阅读器) [0x00000] in :0
在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean 读取标头,System.Object& 结果, System.Runtime.Remoting.Messaging.Header[]& 标头)[0x00000] 在 :0 在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream 序列化流, System.Runtime.Remoting.Messaging.HeaderHandler 处理程序)[0x00000] 在 :0 在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000] in :0 at System.Runtime.Remoting.RemotingServices.DeserializeCallData (System.Byte[] 数组) [0x00000] in :0 at (wrapper xdomain-dispatch) System.AppDomain:DoCallBack (object,byte[]&,byte[]&)

在 [0] 处重新抛出异常:---> System.ArgumentException:无法 绑定到方法“SetHostingEnvironment”。在 System.Delegate.GetCandidateMethod(System.Type 类型,System.Type 目标,System.String 方法,BindingFlags bflags,布尔忽略大小写, Boolean throwOnBindFailure) [0x00000] in :0 at System.Delegate.CreateDelegate(System.Type 类型,System.Type 目标, System.String 方法,布尔型 ignoreCase,布尔型 throwOnBindFailure) [0x00000] in :0 在 System.Delegate.CreateDelegate (System.Type 类型,System.Type 目标,System.String 方法)[0x00000] 在 :0 在 System.DelegateSerializationHolder+DelegateEntry.DeserializeDelegate (System.Runtime.Serialization.SerializationInfo 信息)[0x00000] 在 :0 在 System.DelegateSerializationHolder..ctor (System.Runtime.Serialization.SerializationInfo 信息,StreamingContext ctx) [0x00000] in :0 at (wrapper 托管到本机) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) 在 System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr,System.Reflection.Binder 绑定器,System.Object[] 参数,System.Globalization.CultureInfo 文化)[0x00000] 在 :0 --- 内部异常堆栈跟踪结束 ---
在(包装器 xdomain-invoke)System.AppDomain:DoCallBack (System.CrossAppDomainDelegate) 在 (wrapper) remoting-invoke-with-check) System.AppDomain:DoCallBack (System.CrossAppDomainDelegate) 在 System.Web.Hosting.ApplicationHost.CreateApplicationHost (System.Type hostType, System.String virtualDir, System.String physicalDir) [0x00000] 在 :0 处 Mono.WebServer.VPathToHost.CreateHost (Mono.WebServer.ApplicationServer 服务器,Mono.WebServer.WebSource webSource) [0x00000] in :0 at Mono.WebServer.XSP.Server.RealMain (System.String[] args, Boolean root, IApplicationHost ext_apphost, Boolean quiet) [0x00000] in :0 在 Mono.WebServer.XSP.Server.Main (System.String[] args) [0x00000] in :0

【问题讨论】:

    标签: asp.net razor mono nginx fastcgi


    【解决方案1】:

    在您的 nginx 配置中,执行此操作

    fastcgi_index   /;
    

    而不是这个:

    fastcgi_index Default.aspx;
    

    而不是这个:

    fastcgi_index Views/Home/;
    

    您希望 mono fastcgi 服务器查看基本请求。在 mvc3-land 中,没有 Default.aspx,因为一切都是通过路由完成的。所以,也删除这一行:

    index index.html index.html default.aspx Default.aspx Index.cshtml;
    

    另一件真正让您感到困扰的是,存在对运行时 2 .dll 的底层程序集引用,这些引用已在您的项目引用的库中编译。

    当我发现来自 nuget 的 nhibernate 引用实际上是 3.5 个 .dll 时,我自己也发现了这一点。这使得在一个库中,只有一些类型能够被加载,而其他类型则抛出了与实际发生的事情无关的疯狂异常。我是通过使用 csharp 控制台找到的。

    让我了解潜在问题的第一个例外是:

    System.TypeLoadException: Could not load type
        at (wrapper managed-to-native) System.Type:type_is_assignable_from (System.Type,System.Type)
    

    【讨论】:

    • 关于fastcgi_index,我认为只是删除该行是一样的。
    【解决方案2】:

    404 网址是“/Default.aspx/”

    因为它有它/在最后它正在寻找一个目录,我猜你希望它寻找一个文件 Default.aspx 而不是?

    你的 fastcgi 连接的 nginx 配置块是什么样的?

    更新(在添加请求的信息后):

    http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_index 解释了 fastcgi_index 指令。你设置它的方式有点奇怪你添加 Views/Home/ 到任何目录的 $fastcgi_script_name。

    您可能希望将您的 fastcgi_index 设置为 Default.aspx(然后它将对目录的任何请求传递为 directory/default.aspx,我认为这是您想要的)

    你也没有设置你的 script_filename,mono 可能使用它来知道要运行哪个文件(无论如何,这就是它与 php/ruby fastcgi 一起工作的方式)。

    您可能希望在 location 块中为您的 nginx 参数设置如下内容:

    fastcgi_index Default.aspx;
    fastcgi_param SCRIPT_FILENAME $HOME/WWW/dev/home/$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:8000;
    include /etc/nginx/fastcgi_params;
    

    (如果我正确阅读了您的教程,SCRIPT_FILENAME 可能只是 $fastcgi_script_name)

    顺便说一句,通常你会在 serverblock 级别设置一次 index 和 root 指令,这样你就不必为每个 location 块重复它,但由于你只有一个 location 块,它没有真的很重要。

    【讨论】:

    • 抱歉,回复时间长,我没有看到有人留下回复。我用你要求的东西更新了主要问题,现在它不再寻找 Default.aspx/
    • 好的,所以现在它正在将请求传递给单声道,单声道崩溃,这解释了 nginx 中的网关错误(单声道没有发送请求,因此 nginx 该进程已关闭)-> 主要问题是当前在您的单声道代码中,因为它在传入请求时崩溃
    • 那么也许我不了解单声道的基本知识,但我只是使用 Visual Studio Web Developer 生成的示例代码(使用 .net 4.0)。我的主要目标是让我的网站使用 Razor 视图引擎和 mono
    • 可能发生的事情是您的单码正在获取一些它不期望的 url 并在该 URL 上崩溃,这将是错误。始终检查您的输入,如果出现意外则返回错误。我根据您发布的 ngingx 配置更新了我的答案,如果有帮助,请尝试。
    • Razor 视图引擎没有给我 Default.aspx。我有cshtml文件。这也不是我的代码,这是 Visual Studio Web Developer 生成的默认代码,所以我认为它应该可以工作。这是我遵循的教程:sourcecodebean.com/archives/…
    猜你喜欢
    • 1970-01-01
    • 2011-03-12
    • 2021-03-29
    • 2014-01-25
    • 2017-06-23
    • 2019-10-03
    • 2020-11-12
    • 2019-06-07
    • 2019-05-19
    相关资源
    最近更新 更多