Chinaunix首页 | 论坛 | 博客
  • 博客访问: 140453
  • 博文数量: 68
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 720
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-28 20:01
文章分类

全部博文(68)

文章存档

2015年(68)

我的朋友

分类: 系统运维

2015-08-31 19:07:21

网站的结构是这样的:

---LVS--->nginx-->tomcat

nginx在http区的proxy_set_header配置:

------------------------------------------

proxy_set_header        Host $host;

proxy_set_header        X-Real-IP $remote_addr;

proxy_set_header        Source $remote_addr;

proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header        User-Agent $http_user_agent;

proxy_set_header        Referer $http_referer;

------------------------------------------

后端tomcat的log配置:

Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"

               prefix="access." suffix=""  fileDateFormat="yyyy-MM-dd-HH"

               pattern="%{x-forwarded-for}i %h %t "%r" %s %b %D "%{referer}i" "%{User-Agent}i""

               resolveHosts="false"/>


因为同样的结构与配置之前也用到过,按说这样的配置是没问题的,但这个就是死活log不下源IP(x-forwarded-for),折腾一段时间,突然看到nginx的配置有条

location / {

            proxy_set_header Host $host;

            proxy_pass 

        }

我日,这条”proxy_set_header Host $host;”什么时候加上去的?把它去删除、reload nginx,测试ok。

注意了,proxy_set_header可用在http、server与location区,可以从高到低继承,即是说http的proxy_set_header配置可以被server与location所继承。但是,重点来了,这个继承只存在于server和location没有proxy_set_header指令的基础上。

即是说,这次遇到的后端的tomat日志记录不到源IP问题在于,我上面在http区的proxy_set_header配置没被下面的虚拟主机继承,http头的X-Forwarded-For根本就没传到后端的tomcat。

阅读(432) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~