Nginx反向代理后,tomcat获取到真实IP的方法

Nginx 修改nginx.conf文件

location / {
       proxy_pass http://balance;
       proxy_redirect off;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   add_header 'Access-Control-Allow-Origin' '*';
   add_header 'Access-Control-Allow-Credentials' 'true';
   add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
   add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

        }


Tomcat修改 server.xml


               unpackWARs="true" autoDeploy="true">
                       prefix="localhost_access_log" suffix=".txt"
               pattern="%{X-Real-IP}i  %l %u %t "%r" %s %b" />



     


你可能感兴趣的:(项目心得)