nginx 获取前端真实ip

http {

#指定接收来自哪个前端发送的 IP head 可以是单个IP或者IP段
set_real_ip_from 10.168.38.0/24;
set_real_ip_from 10.132.44.0/24;
#此指令设置了IP地址头转发替换使用
real_ip_header X-Forwarded-For;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
          '$status $body_bytes_sent "$http_referer" '
          '"$http_user_agent" "$http_x_cookie" "$request_time" "$upstream_response_time" "$upstream_cache_status" "$uid"';

location ^~ /wdzjnews/ {
  proxy_pass http://wdzjnews;
  proxy_set_header Host $host:$server_port;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header REMOTE-HOST $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

 

posted @ 2015-01-23 16:29  xiaohui163  阅读(458)  评论(0编辑  收藏  举报