1
我在nodejs中創建了應用程序並部署在IIS上 我無法獲得客戶端。 我已經嘗試了很多模塊和SO答案,但仍然沒有用。如何在IIS上的nodeJS中獲取客戶端ip
服務器代碼
var express = require('express');
var app = express();
var requestIp = require('request-ip');
var ip = require("ip");
var get_ip = require('ipware')().get_ip;
//app.enable('trust proxy');
app.get('/', function(req, res) {
var op = {
op: [
req.headers["X-Forwarded-For"],
req.headers["x-forwarded-for"],
req.client.remoteAddress,
ip.address(),
requestIp.getClientIp(req),
get_ip(req),
req.ip,
req.ips,
1122 //hard coded number.
]
}
res.send(op);
});
var server = app.listen(4000, function() {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http' + host + port);
});
在IIS上部署,這是回答
{
"op": [null,
null,
null,
"216.157.123.123", //server ip
null,
{ "clientIp": "127.0.0.1", "clientIpRoutable": false },
null,
[],
1122]
}
做我需要配置IIS的東西。