如何从http请求对象中获取客户端的IP地址?
IE:
IE:
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('../../lib/node-http-proxy');
//
// Http Server with proxyRequest Handler and Latency
//
var proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) {
// GET IP address here
// var ip = ??
var buffer = httpProxy.buffer(req);
setTimeout(function () {
proxy.proxyRequest(req, res, {
port: 9000,
host: 'localhost',
buffer: buffer
});
}, 200);
}).listen(8004);
X-Forwarded-For
。它在大多数缓存代理中默认支持,并且可以在nginx中进行配置:proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- Eric Elliott