AWS just added support to ELB用于PROXY protocol,它封装TCP并添加客户机IP地址(如代理所见),这样后端服务器就可以访问客户机的IP (因为否则它只会看到ELB的IP)。
我知道ELB可以在HTTP(S)模式下运行,其中ELB插入一个X-Forwarded-For头,但是我以TCP模式运行我的ELB,这样我就可以通过SPDY为我的站点服务。
我如何修改我的node.js应用程序(使用快递)来使用代理协议?
发布于 2013-07-31 22:16:44
I made a module caled proxywrap,它包装node.js Server并自动从连接的流中剥离代理协议头,并将socket.remoteAddress和socket.remotePort重置到代理标头中的值。
它与内置的Server模块(如http、https和net)一起工作,作为模块的插入替代:
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);它还与spdy module一起工作。
var proxiedSpdy = require('proxywrap').proxy(require('spdy').server);当然,你必须使用enable the PROXY protocol on your ELB (或者你的应用程序后面的任何代理)。
https://stackoverflow.com/questions/17981943
复制相似问题