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
}

 

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM