1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
http {

#创建缓存区
proxy_cache_path /tmp/nginxcache levels=1:2 keys_zone=ysnows_cache:10m
max_size=10g inactive=60m use_temp_path=off;

upstream local { # 定义上游服务器组
    server 192.168.50.11:8080
    server 192.168.50.12:8080
}

server {
    server_name www.ysnows.com
    listen 80;
    
    location / {
    
        #把一些头部信息传递给上游服务器
        proxy_set_header Host $host; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-ForWarded-For $proxy_add_x_forwarded_for;
        
       #配置缓存
        proxy_cache_key $host$uri$is_args$args;
        proxy_cache_valid 200 304 302 1d;
    
        #将「/」路径下的所有请求反向代理给 local服务器组
        proxy_pass http://local
    }
 }

}