负载均衡实例
1
Syntax: upstream name { ... }
Default: —
Context: http
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com:8080;
server backup1.example.com:8080 backup;
server backup2.example.com:8080 backup;
}
server {
location / {
proxy_pass http://backend;
}
}
主机 | 外网IP | 内网IP | 身份 |
lb01 | 10.0.0.4 | 172.16.1.4 | SLB |
web01 | 172.16.1.7 | web | |
web02 | 172.16.1.8 | web |
[root@web01 ~]# vim /etc/nginx/conf.d/linux.node.com.conf
server {
listen 80;
server_name linux.node.com;
charset utf-8;
server_name linux.node.com;
charset utf-8;
location / {
root /code/node;
index index.html;
}
}
[root@web01 ~]# mkdir -p /code/node
[root@web01 ~]# echo "我是web01......" > /code/node/index.html
2)配置hosts
3)重启
[root@web01 ~]# systemctl restart nginx
4)访问
[root@web02 ~]# vim /etc/nginx/conf.d/linux.node.com.conf
server {
listen 80;
server_name linux.node.com;
charset utf-8;
location / {
root /code/node;
index index.html;
}
}
[root@web03 conf.d]# mkdir /code/node
[root@web03 conf.d]# echo "我是web03......" > /code/node/index.html
[root@web02 ~]# systemctl restart nginx
[root@lb01 ~]# vim /etc/nginx/conf.d/node_proxy.conf
upstream web {
server 172.16.1.7:80;
server 172.16.1.8:80;
}
server {
listen 80;
server_name linux.node.com;
location / {
proxy_pass http://web;
include proxy_params;
}
}
[root@lb01 ~]# vim /etc/nginx/proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
[root@lb01 ~]# systemctl restart nginx
本文来自博客园,作者:六月OvO,转载请注明原文链接:https://www.cnblogs.com/chenlifan/p/13591837.html