---
title: "HTTP_X_REAL_IP"
author: "123003473"
date: "2015-04-20T17:50:33Z"
tags: []
categories: ["行业应用"]
slug: "http-x-real-ip"
draft: false
lastmod: "2015-04-20T17:50:33Z"
id: 2204238
url: "https://hck.iteye.com/blog/2204238"
---

$_SERVER;得到的都是服务器的地址

$_SERVER;得到的都是客户端的地址

nginx 代理模式下，获取客户端真实IP
在nginx中设置:

proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

后端程序可以从Server变量HTTP_X_REAL_IP和HTTP_X_FORWARDED_FOR中获取用户的ip地址。

HTTP_X_REAL_IP的值是nginx得到的用户REMOTE_ADDR

参考地址：http://doubao.javaeye.com/blog/427619