记录学习搭建nginx负载均衡分发服务器的过程笔记
1.服务器IP:192.168.31.202(当前需要搭建nginx负载均衡分发的服务器)安装好nginx
2.在服务器IP:192.168.31.202的nginx配置文件中添加如下
upstream www.nginx.com{
server 192.168.31.200:80 weight=1;
server 192.168.31.199:80 weight=1;
}
server {
listen 80;
server_name www.nginx.com;
location / {
proxy_pass http://www.nginx.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;
}
}
3.重启nginx , 完成!
到此,服务器IP:192.168.31.202搭建nginx负载均衡分发服务器就完成了
现在,我们把域名www.nginx.com指向IP:192.168.31.202,每次访问域名www.nginx.com时,nginx负载均衡分发服务器就会把请求分发到不同服务器
注意:192.168.31.200:80和192.168.31.199:80这两台服务器都是正常搭建了web服务器的,服务器IP:192.168.31.202(nginx负载均衡分发的服务器)只是把请求分发到不同的服务器而已
---------------------------------------------------------------------------
upstream go {
server 127.0.0.1:8080;
server 192.168.1.1:8080;
}
server {
server_name go.com;
listen 80;
location / {
proxy_pass http://go;
proxy_set_header Host $host;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}