---
title: "nginx upstream 配置"
author: "hello_world_hello"
date: "2015-01-16T10:19:10Z"
tags: []
categories: ["编程语言"]
slug: "nginx-upstream"
draft: false
lastmod: "2015-01-16T10:28:59Z"
id: 2176465
url: "https://hello-world-hello.iteye.com/blog/2176465"
---

1\) nginx upstream 配置

    nginx 作为作为负载均衡使用可有一下配置参数：

 

   负载策略：

   轮询（默认）：根据请求的先后顺序轮询分配到不同服务器  
   weight:  指定权重，根据不同的权重进行轮询分配

   ip\_hash: 根据不同的ip进行分配，同一个ip会使用同一个服务器，可共享session

      
    down : 表示该服务器暂不接受请求  
    weight: 作为负载均衡每个服务器接受用户请求的权重，值越大，分到的概率越大  
    backup:表示所有服务已down或者忙得是够使用该服务器。

    max\_fails：最大失败次数，达到最大失败次数该服务暂停

    fail\_timeout: 达到max\_fails时，该服务暂停的时间  
    

 

    upstream serverName {

          server: 192.168.1.2:8080 weight=1 max\_fails=2 fail\_timeout=60s;

          server:192.168.1.3 down;  
           server: 192.168.1.4 backup;

     }