对于nginx+tomcat这种架构,如果后端tomcat配置保持默认,那么tomcat的访问日志里,记录的就是前端nginx的IP地址,而不是真实的访问IP。因此,需要对nginx、tomcat做如下配置:
1)nginx配置 在nginx.conf配置中修改
server{
listen 80;
server_name www.abc.com;
location / {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://192.168.0.67:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
2)tomcat配置 在server.xml文件中<host></host>中,修改原有内容如下
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%{X-FORWARDED-FOR}i %l %u %t %r %s %b %D %{User-Agent}i" resolveHosts="false" />
知行办公,专业移动办公平台
【总监】十二春秋之,3483099@qq.com;
【Master】zelo,616701261@qq.com;
【运营】运维艄公,897221533@qq.com;
【产品设计】流浪猫,364994559@qq.com;
【体验设计】兜兜,2435632247@qq.com;
【iOS】淘码小工,492395860@qq.com;iMcG33K,imcg33k@gmail.com;
【Android】人猿居士,1059604515@qq.com;思路的顿悟,1217022114@qq.com;
【java】首席工程师MR_W,feixue300@qq.com;
【测试】土镜问道,847071279@qq.com;
【数据】喜乐多,42151960@qq.com;
【安全】保密,你懂的。
本文出自 “运维艄公” 博客,请务必保留此出处http://bluemooder.blog.51cto.com/12822812/1965405
原文地址:http://bluemooder.blog.51cto.com/12822812/1965405