---
title: "Nginx负载均衡与反向代理的例子(图文)"
author: "李雨泽"
date: "2014-01-03T19:16:06Z"
tags: []
categories: ["开源软件"]
slug: "nginx"
draft: false
lastmod: "2014-01-03T19:17:35Z"
id: 1998836
url: "https://lichunhui.iteye.com/blog/1998836"
---

[Nginx](http://www.jbxue.com/server/nginx/)负载均衡与反向代理，配置内容如下：

1，设置在http段：        

```
upstream my_server_pool {
  server 192.168.10.21:80 weight=1 max_fails=2 fail_timeout=30s;
  server 192.168.10.20:80 weight=1 max_fails=2 fail_timeout=30s;
  proxy_cache_path /usr/local/nginx/proxy_temp levels=1:2   keys_zone=cache_one:500m  inactive=1d   max_size=1g;
}
```

 

2，设置在server段：  
 

```
location /sms {
  proxy_pass http://my_server_pool;
  proxy_set_header Host $host;
  proxy_cache cache_one;
  proxy_set_header X-Forwarded-For $remote_addr;
  proxy_cache_valid 200 10m;
  proxy_cache_valid 304 1m;
  proxy_cache_valid 301 302 1h;
  proxy_cache_valid any 1m;
  proxy_cache_key $host$uri$is_args$args;
}
```

 

测试结果，如下图：  
![nginx负载均衡与反向代理](http://www.jbxue.com/d/file/server/nginx/20130809081556.png)![<a href=http://www.jbxue.com/article/2652.html target=_blank class=infotextkey>nginx反向代理</a>](http://www.jbxue.com/d/file/server/nginx/20130809081534.png)