如何进行故障排除"无法检查Phoenix.Socket transport"消息?

时间:2016-06-20 17:56:06

标签: elixir phoenix-framework

我得到了很多"无法检查Phoenix.Socket transport"消息。这似乎表明某些东西正在袭击我的服务器,但请求中的主机名与我配置的主机名不匹配。我该如何调试?我怎样才能知道这些请求来自哪里,或者这些请求是什么,或者他们要求的是什么?它并没有在"无法检查原点中告诉我这些......"信息。我也没有得到任何其他记录更多信息。 Phoenix是否记录了收到的所有请求,以便我可以看到即将发生的事情?

1 个答案:

答案 0 :(得分:3)

我认为这可能会对您有所帮助:https://github.com/phoenixframework/phoenix/issues/1359

master中已有更多描述性错误消息:https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/socket/transport.ex#L360

    This happens when you are attempting a socket connection to
    a different host than the one configured in your config/
    files. For example, in development the host is configured
    to "localhost" but you may be trying to access it from
    "127.0.0.1". To fix this issue, you may either:
      1. update [url: [host: ...]] to your actual host in the
         config file for your current environment (recommended)
      2. pass the :check_origin option when configuring your
         endpoint or when configuring the transport in your
         UserSocket module, explicitly outlining which origins
         are allowed:
            check_origin: ["https://example.com",
                           "//another.com:888", "//other.com"]

我不确定在Phoenix中是否有一种简单的方法可以记录因原点而丢弃的请求,但我会使用Erlang中的:dbg

:dbg.tracer #start tracer
:dbg.p(:all, :c) #print all matching calls
:dbg.tpl(Phoenix.Socket.Transport, :check_origin, 5, [])
#match on Module, :function, arity, (no additional options)

check_origin的第一个参数是Plug.Conn,其中应包含{<<"origin">>, <<"http://localhost:4000">>},之类的内容。

Phoenix live reload机制使用websockets,所以当我在check_origin: false中更改config/dev.exs时,我会收到很多这些内容。