标签:
1.场景
nginx3连接广域网其他服务器在内网
nginx 1 ---------------------
/ \ \ \
server 1 server 2 server3 nginx3 <--
\ / / /
nginx 2 -----------------------
2.思路
nginx3为入口反向代理、负载均衡到 nginx1、2
nginx 1、2 反向代理并负载均衡 servier1、2、3
3.配置文件
nginx3配置:
upstream lb.tin.com {
server 10.221.148.167:80; #nginx1
server 10.251.216.232:80; #nginx2
}
upstream pro1.tin.com {
server 10.221.148.167:80;
}
upstream pro2.tin.com {
server 10.251.216.232:80;
}
server {
listen 80;
server_name loalhost;
location /pro1 {
proxy_pass http:// pro1.tin.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /pro2 {
proxy_pass http:// pro2.tin.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
nginx1、2配置:
nginx1例:
upstream pro1.tin.com {
server 10.221.148.160:8080; #server1
server 10.251.216.230:8080; #server2
server 10.251.216.231:8080; #server3
}
upstream server1.tin.com {
server 10.221.148.160:8080;
}
upstream server2.tin.com {
server 10.251.216.230:8080;
}
upstream server3.tin.com {
server 10.251.216.231:8080;
}
server {
listen 8080;
server_name loalhost;
location /server1 {
proxy_pass http:// server1.tin.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /server2 {
proxy_pass http://server2.tin.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /server3 {
proxy_pass http://server3.tin.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
标签:
原文地址:http://www.cnblogs.com/tintindeng/p/4964366.html