remote_ip 和 peer 有什么区别?
What's the difference between remote_ip and peer?
我正在编写一个插件,将访问日志放入一个文件中,就像普通的 Web 服务器一样。 conn
作为客户端IP地址的数据源,有remote_ip
和peer
。我应该使用哪个,它们之间有什么区别?
是否有关于conn
中各个实体的文档描述?
另外,我的插件像下面的片段,从Elixir/Phoenix的角度来看是不是很自然?
Logger.info(
Enum.join([
"type:" <> "request",
"remoteip:" <> Enum.join(Tuple.to_list(conn.remote_ip), ","),
"method:" <> conn.method,
"path:" <> conn.request_path,
"status:" <> to_string(conn.status),
"size_res:" <> to_string(byte_size(to_string(conn.resp_body))),
], ",")
)
来自 Plug.Conn 文档:
peer - the actual TCP peer that connected, example: {{127, 0, 0, 1}, 12345}. Often this is not the actual IP and port of the client, but rather of a load-balancer or request-router.
remote_ip - the IP of the client, example: {151, 236, 219, 228}. This field is meant to be overwritten by plugs that understand e.g. the X-Forwarded-For header or HAProxy’s PROXY protocol. It defaults to peer’s IP.
如果您使用的是负载平衡器(例如 http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/x-forwarded-headers.html),那么 peer
IP 地址将指的是负载平衡器而不是客户端。负载均衡器在 header(AWS 的 X-Forwarded-For
)中提供客户端的实际 IP 地址,该地址将作为 remote_ip
.
存储在 Plug.Conn 结构中
我正在编写一个插件,将访问日志放入一个文件中,就像普通的 Web 服务器一样。 conn
作为客户端IP地址的数据源,有remote_ip
和peer
。我应该使用哪个,它们之间有什么区别?
是否有关于conn
中各个实体的文档描述?
另外,我的插件像下面的片段,从Elixir/Phoenix的角度来看是不是很自然?
Logger.info(
Enum.join([
"type:" <> "request",
"remoteip:" <> Enum.join(Tuple.to_list(conn.remote_ip), ","),
"method:" <> conn.method,
"path:" <> conn.request_path,
"status:" <> to_string(conn.status),
"size_res:" <> to_string(byte_size(to_string(conn.resp_body))),
], ",")
)
来自 Plug.Conn 文档:
peer - the actual TCP peer that connected, example: {{127, 0, 0, 1}, 12345}. Often this is not the actual IP and port of the client, but rather of a load-balancer or request-router.
remote_ip - the IP of the client, example: {151, 236, 219, 228}. This field is meant to be overwritten by plugs that understand e.g. the X-Forwarded-For header or HAProxy’s PROXY protocol. It defaults to peer’s IP.
如果您使用的是负载平衡器(例如 http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/x-forwarded-headers.html),那么 peer
IP 地址将指的是负载平衡器而不是客户端。负载均衡器在 header(AWS 的 X-Forwarded-For
)中提供客户端的实际 IP 地址,该地址将作为 remote_ip
.