记一次用nginx做负载均衡、灾备处理

直接上代码吧,关键的地方都标有注释,有点基础的人应该都能看懂,配置如下:

http {
    ...//只上关键代码
    upstream localhost {
       server 192.168.1.215:8080 weight=1; #这里就保障的负载均衡
       server 192.168.1.215:8081 weight=1;
     }

     server {
        ...//只上关键代码
        location / {
            root   dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
   	        proxy_connect_timeout       1; #这里就保证了自动切换服务器
            proxy_read_timeout          1;
            proxy_send_timeout          1;
        }

        location /sys/ {
            proxy_pass http://localhost/sys/;
   	        proxy_connect_timeout       1; #这里就保证了自动切换服务器
            proxy_read_timeout          1;
            proxy_send_timeout          1;
        }
    }
}

 

你可能感兴趣的:(服务器)