remote_addr variable

Francis Daly francis at daoine.org
Sun Oct 25 11:20:23 UTC 2020


On Mon, Oct 19, 2020 at 11:23:23AM +0200, A. Schulze wrote:

Hi there,

> I like to display (using ssi) if a client's remote address is ipv4 or ipv6
> Is there a variable available that indicate the current transport protocol?

I'm not aware of a ready-made variable for this; but you can probably use
"map" to make your own.

For example -- if you are happy to say that when $remote_addr includes
a : it is IPv6, otherwise it is IPv4; then at http{} level you could do
something like

  map $remote_addr $this_transport_is {
    ~: IPv6;
    default IPv4;
  }

and then use $this_transport_is where you want it.

(Note: I have tested this with

  return 200 "Transport: $this_transport_is\n";

but I have not tried ssi.)

> Any hint is appreciated!

Note - you may prefer to say "if $remote_addr includes a dot, it is IPv4,
else it is IPv6. And you may or may not care about listening on unix
domain sockets. Adjust the "map" to match whatever definition you like.

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list