What is the difference between remote_ip and peer?

I am writing a fork that places an access log into a file, such as a mediocre web server. The client connhas remote_ipand as the source of data peer. What should I use and what is the difference between them?

Are there any documents describing each object in conn?

In addition, my plugin is similar to the following snippets, is this natural from the point of view of the 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))),
  ], ",")
)
+4
source share
1 answer

From Plug.Conn docs:

peer is the actual TCP host connected, for example: {{127, 0, 0, 1}, 12345}. Often this is not the actual IP and port of the client, but rather a load balancing or request-router.

remote_ip - IP- , : {151, 236, 219, 228}. , , . X-Forwarded-For HAProxys PROXY. IP-.

(, http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/x-forwarded-headers.html), peer ip . IP- (X-Forwarded-For AWS), Plug.Conn remote_ip.

. https://tools.ietf.org/html/rfc7239

+7

Source: https://habr.com/ru/post/1622709/


All Articles