码迷,mamicode.com
首页 > 其他好文 > 详细

nginx记录真是的IP地址 <备忘>

时间:2015-08-06 13:33:56      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:nginx记录真实客户ip

nginx、haproxy等作为代理服务器时,要使后端web服务器记录真是的IP地址,需要配置:

location / {
    proxy_set_header    Host    $host;
    proxy_set_header    X-Real-IP    $remote_addr;
    proxy_set_header    X-Forwarded-For    $proxy_add_x_forwarded_for;
    proxy_buffering    off;
    proxy_pass    http://bloke;
}

后端web服务器配置:

    nginx:

log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    apache:

    将:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

    改为:

LogFormat "%{X-Real-IP}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined


nginx记录真是的IP地址 <备忘>

标签:nginx记录真实客户ip

原文地址:http://anonxiaozi.blog.51cto.com/8139771/1682164

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!