node.js - Why is X-Forwarded-For header not getting set by node-express proxy? -


i have single node file following:

it listens on 2 ports: 80 , 443 (for https). redirects connections on 80 443.

and on 443 reverse proxy round-robin redirects several local servers on plain http.

the problem have in actual target servers, unable actual remote ip address of browser. address of reverse proxy. request made reverse proxy, thats expected guess.

so, did following in reverse proxy (only relevant code lines shown):

    proxy = httpproxy.createserver();      var https_app = express();     https.createserver(sslcerts, https_app).listen(443, function () {      ...     });       https_app.all("/",function(req, res) {         ...         //res.append('x-forwarded-for',req.connection.remoteaddress);         proxy.web(req,res, {target: local_server});         ...     } 

i need res.append('x-forwarded-for',req.connection.remoteaddress) proxy server.. in request header. issue of setting address secondary. first need set header can read target server. proxy not set header, think should default. or should it? or , doing wrong read it?

i cannot see definition of proxy, i'm assuming same following code, using express-http-proxy. expect alternative method work you:

var proxy = require('express-http-proxy');  var myproxy= proxy('localhost:443', {     forwardpath: function (req, res) {         return require('url').parse(req.url).path;     } }); 

and simply:

app.use("/*", myproxy); 

i hope helps.


Comments