node.js - How do I use the PROXY protocol to get the client's real IP address? -
aws added support elb proxy protocol, wraps tcp streams , adds client ip address (as seen proxy) backend server has access client's ip (since otherwise see elb's ip).
i know elb can run in http(s) mode, elb inserts x-forwarded-for
header, run elbs in tcp mode can serve site on spdy.
how can modify node.js app (using express) use proxy protocol?
i made module caled proxywrap wraps node.js server
s , automatically strips proxy protocol headers connections' streams, , resets socket.remoteaddress
, socket.remoteport
values found in proxy headers.
it works built-in server
modules (like http
, https
, , net
) drop-in replacement module:
var http = require('http') , proxiedhttp = require('proxywrap').proxy(http) , express = require('express') , app = express() , srv = proxiedhttp.createserver(app); // instead of http.createserver(app) app.get('/', function(req, res) { res.send('ip = ' + req.connection.remoteaddress + ':' + req.connection.remoteport); }); srv.listen(80);
it works spdy module:
var proxiedspdy = require('proxywrap').proxy(require('spdy').server);
of course, you'll have enable proxy protocol on elb (or whatever proxy app behind).
Comments
Post a Comment