5
5
5etroff2015-02-09 14:21:59
Java
5etroff, 2015-02-09 14:21:59

How to pass the real ip address of the client through nginx to tomcat?

One server has nginx and tomcat installed. The problem is that nginx passes the address 127.0.0.1 to tomcat (this can be seen in the tomcat logs). An application that runs on tomcat needs real ip addresses of clients. Prior to this, apache was used instead of nginx and real ip addresses of clients were transmitted through it to tomcat.
Fragment of nginx config:

location / {
        ...
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        ...
        proxy_pass http://localhost:8080/;
        ...
    }

I added the following line to server.xml:
<Valve className="org.apache.catalina.valves.RemoteIpValve"  />

Didn't give any result.
Tell me what settings you need to make with nginx or tomcat, so that in tomcat the real ip address of clients through nginx, without writing filters and without touching the application, only software settings?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
3
3vi1_0n3, 2015-02-09
@5etroff

Something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question