Welcome! Log In Create A New Profile


how to set remote addr of client ip in nginx

Posted by Noone 
how to set remote addr of client ip in nginx
July 30, 2020 06:44AM
I'm using nginx as a load balancer for my web application.

My request flow will be like : User --> Nginx --> Tomcat. I'm trying to get client ip address with "request.getRemoteAddr()" in my java application. However I'm getting nginx server ip as remote address.

I tried real ip solution and header overwrite , none of them seems worked.

My nginx conf
real_ip_header X-Forwarded-For;

upstream backend {
server xxxxxx;

server {
listen 80;
listen 443;
server_name xxxxxx;

location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_read_timeout 100;

I can see the correct remote address of client in nginx log. I am able to set the client ip in some other custom header and access it in my java application. But I want the correct client ip in "request.getRemoteAddr()" instead of nginx server ip. Can someone please help?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 66
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready