使用HAProxy 1.5,是否可以添加一个请求头,其值是绑定使用通配符的前端使用的IP地址?
例如,给定以下configuration,是否有我replace“%[fe_id]”与为了得到用于连接到前端的variablesIP地址?
frontend localhost bind *:80 bind *:443 ssl crt /etc/ssl/ssl.pem mode http default_backend nodes option forwardfor backend nodes mode http balance roundrobin http-request add-header X-FrontEnd-IP %[fe_id] server web00 10.1.10.15:80 check server web01 10.1.10.16:80 check server web02 10.1.10.17:80 check
我想到了。 不知道我错过了这个,但variables是“dst”。 所以得到的configuration如下所示:
frontend localhost bind *:80 bind *:443 ssl crt /etc/ssl/ssl.pem mode http default_backend nodes option forwardfor backend nodes mode http balance roundrobin http-request add-header X-FrontEnd-IP %[dst] server web00 10.1.10.15:80 check server web01 10.1.10.16:80 check server web02 10.1.10.17:80 check
这样我们就可以看到请求是来自networking内部还是外部,Web服务器可以相应地进行调整。
此外,要使用PHP访问这个variables,就像使用带有“HTTP_X_FRONTEND_IP”键的$ _SERVER数组一样简单。
$_SERVER['HTTP_X_FRONTEND_IP']