Blogger Information
Blog 16
fans 0
comment 0
visits 14501
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
反向代理和负载均衡
进击的小菜鸟
Original
640 people have browsed it

nginx支持两个用法  1个proxy_pass,1个upsteam,分别用来做反向代理,和负载均衡

以反向代理为例,nginx不自己处理php的相关请求,而是把php的相关请求转发给apache来处理.

例如  :有两台服务器  

客户端--->  (服务器1)nginx(只处理html文件) ---proxy_pass--->(服务器2)apache(处理php)

nginx配置 

location ~ \.php {

    proxy_pass   http://127.0.0.1:8080

}

反向代理后端如果有多台服务器,自然可形成负载均衡,

把多台服务器用 upstream绑定在一起并起个组名,然后proxy_pass指向这个组名

例:两台图片服务器

up_steam  img_server(组名) {

server  127.0.0.1:81  weight=1(权重) max_fails=2(最多几次无法连接就放弃连接)

    fail_timeout=3 (连接失败连接时间秒);

server  127.0.0.1:82  weight=1(权重) max_fails=2(最多几次无法连接就放弃连接)

    fail_timeout=3 (连接失败连接时间秒);

}

location ~ \.(jpg|png) {

proxy_set_header  X-Forwarded-For $remote_addr;(后端服务器得到的ip是前端服务器的ip,所以发送请求头给后端服务器)

proxy_pass  http://img_server;

}

默认的负载均衡的算法很简单,就是针对后端服务器的顺序,逐个请求.也有其他算法,如一致性哈希,需要安装第三方模块.


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!