Reputation: 10075
I have a single node file which does the following:
It listens on two ports: 80 and 443 (for https). It redirects connections on 80 to 443.
And on 443 is a reverse proxy that does a round-robin redirects to several local servers over plain http.
The problem that I have is that in the actual target servers, I am unable to get the actual remote IP address of the browser. I get the address of the reverse proxy. The request is made by the reverse proxy, so thats expected I guess.
So, I did the following in the 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 to do something like res.append('X-Forwarded-For',req.connection.remoteAddress) to the proxy server.. in its request header. The issue of setting the address is secondary. I first need to set the header itself which can be read by the target server. The proxy itself does not set this header, which I think it should by default. Or should it? Or does it and I am doing something wrong to read it?
Upvotes: 1
Views: 3307
Reputation: 6200
I cannot see your definition of proxy
, but I'm assuming it is same as the following code, using express-http-proxy
. I expect this alternative method will work for you:
var proxy = require('express-http-proxy');
var myProxy= proxy('localhost:443', {
forwardPath: function (req, res) {
return require('url').parse(req.url).path;
}
});
And then simply:
app.use("/*", myProxy);
I hope this helps.
Upvotes: 1