今天有2个项目组的研发过来问我怎么设置tomcat日志显示真实ip,因为我们前面有个nginx反向代理,所有tomcat取到的是nginx的ip。需修改2个地方,nginx的配置文件和tomcat的server.xml
nginx nginx.conf中加
-
proxy_set_header X-Forwarded-For $remote_addr;
tomcat server.xml中加
当然你也可以diy日志文件里面的内容,顺序,打印项都可以调整。
-
-
prefix="localhost_access_log." suffix=".txt"
-
pattern="%{X-FORWARDED-FOR}i %l %u %t %r %s %b %D %q %{User-Agent}i %T" resolveHosts="false"/>
测试结果:
-
192.168.20.5 - - [20/May/2013:20:20:32 +0800] POST /stars/login/heartbeat?chatVersion=0&t=1369052176100 HTTP/1.0 500 1344 90 ?chatVersion=0&t=1369052176100 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 0.090
-
192.168.17.6 - - [20/May/2013:20:20:32 +0800] POST /stars/login/heartbeat?chatVersion=0&t=1369052174945 HTTP/1.0 500 1344 89 ?chatVersion=0&t=1369052174945 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 0.089
-
192.168.26.4 - - [20/May/2013:20:20:36 +0800] POST /stars/login/heartbeat?chatVersion=0&t=1369052174946 HTTP/1.0 500 1344 3 ?chatVersion=0&t=1369052174946 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 0.003
阅读(1278) | 评论(0) | 转发(0) |