NGINX四层负载均衡+nginx七层负载均衡+后端web节点,
四层ip 10.0.0.110
172.16.1.110
七层ip 172.16.1.120
webip 172.16.1.130
1.四层配置如下
stream {
upstream web {
server 172.16.1.120:80;
}
server {
listen 80 proxy_protocol;
proxy_pass web;
set_real_ip_from 127.0.0.1;
}
}
2.七层配置如下:
[root@gitlab conf.d]# cat proxy_ip_oldxu.com.conf
upstream ip {
server 172.16.1.130:80;
}
server {
listen 80;
server_name ip.oldxu.com;
location / {
proxy_pass http://ip;
}
}[root@gitlab conf.d]# cat proxy_ip_test.com.conf
upstream ip {
server 172.16.1.130:80;
}
server {
listen 80;
server_name ip.test.com;
location / {
proxy_pass http://ip;
}
}
3.后端web配置如下:
[root@es-node1 conf.d]# cat ip.test.com.conf
server {
listen 80;
server_name ip.test.com;
root /code;
location / {
index index.html;
}
}
配置访问没有问题, 就是希望能透传客户端真实IP地址,使用了proxy_protocol也不行。
展开
作者回复: 你配错了。最外层四层nginx上不应加listen proxy_protocol,因为下游的协议没有使用proxy_protocol协议,对吧?从你的描述上看,应该是四层nginx首先发起proxy_protocol,所以你要加上proxy_protocol on;
七层HTTP接收时要加上listent proxy_protocol