1.只需要在nginx编译安装中加上--with-http_realip_module这一选项

nginx proxy 配置

location / {

proxy_redirect off ;

proxy_set_header Host $host;

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;

client_max_body_size 50m;

client_body_buffer_size 256k;

proxy_connect_timeout 30;

proxy_send_timeout 30;

proxy_read_timeout 60;

proxy_buffer_size 256k;

proxy_buffers 4 256k;

proxy_busy_buffers_size 256k;

proxy_temp_file_write_size 256k;

proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;

proxy_max_temp_file_size 128m;

proxy_pass http://IP

}

2.虚拟主机增加配置
set_real_ip_from nginx_proxy_ip/24;
set_real_ip_from nginx_proxy_ip;
real_ip_header X-Real-IP;

3.php获取ip代码
vi i.php
<?php
echo $_SERVER['REMOTE_ADDR'];

4.然后把i.php放进你网站根目录下,使用浏览器访问http://blog.slogra.com/i.php,就可以看到客户的真实ip地址了.