Nginx 获取负载均衡器后的真实 IP

add_header server-id $hostname always;

server
{
    listen       80;

    server_name  interactive-video..cn;

    index        index.html index.htm;
    root         /data/Interactive-video-api/html/web;

    client_max_body_size 100m;
    client_body_buffer_size 1024k;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;

    gzip_http_version 1.0;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/xml application/xml application/xml+rss text/javascript application/json;

    real_ip_header    X-Forwarded-For;
    set_real_ip_from  192.168.0.0/16;
    set_real_ip_from  172.0.0.0/8;
    real_ip_recursive on;

    location ~ ^(.*)\/\.svn|.git|.gitignore\/ {
        deny all;
    }

    location / {
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.html?s=$1  last;
            break;
        }
    }

    location /apiservice/ {
        proxy_http_version 1.1;
        proxy_pass http://interactive-video-api:8081/;
        proxy_set_header x-forwarded-for $remote_addr;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Upgrade $http_upgrade;
    }

    access_log off;
}