Tuesday, 4 April 2017

Unable to print the IP of a request on an expressjs server behind nginx?

I tried the following solution:

app.enable('trust proxy');
...
console.log(req.ip);                        // gives ::ffff:127.0.0.1
console.log(req.ips);                       // gives []
console.log(req.header('x-forwarded-for')); // gives undefined 
console.log(req.connection.remoteAddress);  // gives ::ffff:127.0.0.1

Is there any other way?

Is this a symptom of a bigger problem?



via Tiago BĂ©rtolo

No comments:

Post a Comment