如何在IIS上的nodeJS中获取客户端IP

时间:2015-10-20 05:25:42

标签: node.js iis express

我在nodejs中创建了应用程序并在IIS上部署 我不能得到客户的支持。 我尝试了很多模块和SO答案,但仍然没用。

服务器代码

 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上配置一些东西。

1 个答案:

答案 0 :(得分:0)

您是否安装了“增强记录”或“高级记录加载项”?

http://loadbalancer.org/blog/iis-and-x-forwarded-for-header