最近在研究nginx的负载均衡和反向代理,先看下这两个简单的配置吧! 负载均衡
5 M1 G% k( N0 T1 |$ x9 T
worker_processes 1; events { worker_connections 1024; } http{ upstream lxx {//默认是80端口 server 192.168.0.62 weight=2; server 192.168.0.161 weight=3; } server { listen 80; location / { proxy_pass http://lxx; } } * S% I. R! i3 o0 z% N
} 3 x7 @, o* z) i9 }; T8 y3 ^/ q
3 m4 j& w+ @ ^' x8 W% B
反向代理 " f- |) g" O1 t( W# x- C7 k/ s3 X( p
worker_processes 1; events { worker_connections 1024; } http{ upstream lxx {//默认是80端口 server 192.168.0.62 weight=2; server 192.168.0.161 weight=3; } server { listen 80; location / { proxy_pass http://lxx; 8 q4 h8 N) M0 D) a% M
#Proxy Settings proxy_redirect off; 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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_max_temp_file_size 0; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } }
2 K# P. M" Q! E}
: A8 o5 J. g9 }8 ^5 w5 b0 g# W/ X# h( {
从配置上来看,它只是多了Proxy Settings下面的一些设置参数!但从实际的表现结果来看,感觉区别并不是很大,负载均衡已经可以把用户的请求按照相关算法和规则发送到web集群的某台机器,而反向代理也是实现了如此的功能,它们的具体的区别在哪里?求普及! - G" I; B( G) p
* o" ~& ?- ?% O! z; Z7 q& O |