Nginx reverse proxy server Tomcat get real IP issues

1.nginx.conf Configuration

Modify Server location configuration

increase

proxy_set_header X-Real-IP $ remote_addr ; # real customer retention before the end of the proxy ip
proxy_set_header the X-Forwarded-the For-$ proxy_add_x_forwarded_for; # recording process agents

    server {
           listen   7777;
           server_name  192.168.10.8:7777;
           location / {
               root   /usr/local/web/dist;
               index  index.html index.htm;
            }
           location /unstructured/ {
                proxy_pass http://192.168.10.8:8080/unstructured/;
                proxy_set_header    X-Real-IP        $remote_addr;
                proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
    
            }
    }

2 Modify the tomcat conf directory server.xml configuration

  Increased Valve className = "org.apache.catalina.valves.RemoteIpValve" Configuration

       Review Valve className = "org.apache.catalina.valves.AccessLogValve" pattern configuration% h --->% {X-Real-IP} i can

			<Valve className="org.apache.catalina.valves.RemoteIpValve"   
                       remoteIpHeader="x-forwarded-for"
                       remoteIpProxiesHeader="x-forwarded-by" />
					   
			<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%{X-Real-IP}i %l %u %t "%r" %s %b" />

  

Through the above two steps of setting, we tomcat log file records localhost_access_log.2019-07-02 can see the true ip address, rather than the original ip nginx services.

 

Guess you like

Origin www.cnblogs.com/liuxiutianxia/p/11119867.html