Get IP Client in a plugin

Hello,

I am a student in IT and for a project I am looking for a way to get the IP Client when I am doing an HTTP Request on Kong.
I read How to Forward Client’s request IP
Maybe I just didn’t understand but I tried to get the IP Client in a log but I always get the same address : 10.0.2.2
I read something about nginx http module but I don’t understand how to use it or if Kong already implemented it.
Is someone have an easy solution ?

Thanks

Please try using ngx.var.remote_addr (reference)

If this does not work, please add more data: how exactly are you getting that 10.0.2.2 IP address? Also please add what version of Kong are you using, and any specifics that you might have: plugins, custom nginx configurations, etc.

The 10.0.2.2 comes from the ngx.var.remote_addr.
Sorry for the lack of informations.
My Kong is started by Docker in a Virtual Box launched with Windows 10.
The version of Kong is 0.13.0.
And for the plugin used, this is a custom plugin. Just a simple hello world in the error logs.
I just add a ngx_log(ngx.ERR, ngx.var.remote_addr).
I tried ngx_log(ngx.ERR, ngx.var.realip_remote_addr), but I still have the same response : 10.0.2.2
My tutor said that maybe it is because of my virtual machine. And after some searches it seems that this is the case. But how can I get the real IP Client ? Because I would like to execute some command depending on the IP address of the Client.

Thanks for your help :slight_smile:

I agree with your tutor’s assessment.

That is more a Docker question than a Kong question. Try disabling the network containerization by using the --network=host option when you create your container. This option is described on the Docker docs

Docker stop immediatly if I use the network option.
But as my tutor and you agree, the problem was my virtual machine.
That is why I made an Nginx Reverse Proxy from my Windows to make my HTTP Request, I use X_FORWARDED_FOR thing to set the ngx.var.http_x_forwarded_for which was nil.
And now I retrieve the good address IP.

Thanks for your help :smiley:.

@i3yaki, please read this: