Welcome! Log In Create A New Profile

Advanced

Set real ip not working

Posted by snir 
snir
Set real ip not working
May 09, 2018 08:30PM
Hello
I want to get the real ip of the client but I'm all ways getting the ip of
the ngnix server.
I trayed using set_real_ip:
http {
upstream myapp1 {
server 177.17.777.13:8080;

}

server {
listen 80;


real_ip_recursive on;

set_real_ip_from 177.17.777.13;
real_ip_header X-Forwarded-For;

location / {
proxy_pass http://myapp1;

}
}



}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,279736,279736#msg-279736

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Francis Daly
Re: Set real ip not working
May 09, 2018 10:40PM
On Wed, May 09, 2018 at 02:19:23PM -0400, snir wrote:

Hi there,

> I want to get the real ip of the client but I'm all ways getting the ip of
> the ngnix server.

What, specifically, do you mean by "getting the ip"?

> I trayed using set_real_ip:

The tcp connection from nginx to upstream will (almost) always come from
an IP address of the nginx machine.

It is possible that nginx can be configured to write a client IP address
into a http header, that the upstream server can then be invited to read.

For that, you will want to make sure to write the client IP address into
a http header (proxy_set_header, perhaps $proxy_add_x_forwarded_for) and
you will want to make sure to configure your upstream server to read it.


For one test request, what is the client IP address that you care
about? Do you see that IP address anywhere in the request from nginx to
upstream? If not, fix that. If so: do you see upstream doing anything
with that part of the request? If not, fix that.

Good luck with it,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
snir
Re: Set real ip not working
May 10, 2018 02:10PM
Thanks
That what I needed
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://myapp1;

}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,279736,279745#msg-279745

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login