反向代理除了实现负载均衡之外,还提供如缓存来减少上游服务器的压力
全局配置proxy_buffering on; proxy_buffer_size 4k; proxy_buffers 512k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 256k; proxy_cache_lock on; proxy_cache_lock_timeout 200ms; proxy_temp_path /tepfs/proxy_temp; proxy_cache_path /tepfs/proxy_cache levels=1:2 keys_zone=cache:512m inactive=5m max_size=8g; proxy_connect_timeout 3s; proxy_read_timeout 5s; proxy_send_timeout 5s;
开启proxy_buffer,缓存内容将存放在tmpfs用来提升性能,设置超时时间
location配置location /backend/.$/{
set_by_lua_file $consistent_key "/export/App/才..cn/lua/lua_balancing_backend.properties"
#失败重试机制
proxy_next_upstream error timeout http_500 http_502 http_504;
proxy_next_upstream_timeout 2s;
proxy_next_upstream_tries 2;
#请求上游服务器使用GET方法(不管请求是什么方法)
proxy_method GET;
#不给上游服务器传递请求体
proxy_pass_request_body off;
#不给上游服务器传递请求头
proxy_pass_request_headers off;
#设置上游服务器的哪些响应头不发送给客户端
proxy_hide_header_Vary;
#支持keep_alive
proxy_http_version 1.1
proxy_set_header Connection "";
#给上游服务器传递Referer、cookie、和Host(按需传递)
proxy_set_header Referer $http_referer;
proxy_set_header cookie $http_cookie;
proxy_set_header Host web.3.cn.local;
proxy_pass http://backend /$1$is_args$args;
}



