nginx 反向代理 和lvs负载均衡

nginx反向代理:用户请求nginx代理服务器然后代理服务器将用户请求转为服务器再由nginx代理服务器将服务器的响应反应给用户。

lvs负载均衡:用户请求nginx代理服务器然后代理服务器将用户请求转为服务器再由服务器直接响应用户的请求

nginx反向代理用的是ngx_http_upstream_module module is used to define groups of servers that can be referenced by the proxy_passfastcgi_passuwsgi_passscgi_pass, and memcached_pass directives.

在http语块内定义:

upstream web_pools{

       ip_hash;#wrr 默认是rr weight越大接受的请求越多 ip_hash会话保持 #第三方算法 url_hash web缓存  fair 根据后端rs 响应速度分配请求

       server domainname|ip:port weight=2 max_fails=2 fail_timeout=20s#fail_timeout检测失败后多少时间后再次检测 ip_hash时weight无用

       server domainname|ip:port backup;#高可用 ip_hash不支持

}

location / {
    proxy_pass       http://localhost:8000;
    proxy_set_header Host      $host;#后端RS配置有多个虚拟主机时将用户请求的真实host反应给rs
    proxy_set_header X-Forwarded-For $remote_addr;#让后端RS服务器记录访问用户的真实IP apache web  LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  nginx web 会自动记录真实IP
}

 


posted @ 2016-11-09 11:47  howhy  阅读(2219)  评论(0编辑  收藏  举报