`
cocos
  • 浏览: 404181 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

Nginx的负载均衡配置范例

阅读更多
    server {
        listen       80;
        server_name tc.test.nd ;

        location / {
           proxy_pass http://gwy.test.nd; 
        }
    }
 

 

 

 

upstream load_balance {
        server localhost:8088 ;
        server 192.168.1.4:8080 down;
        server home.ucenter weight=2;
        server backserver:9100 backup;
        
}
server {
        listen 80;
        #location / {
        #       proxy_pass http://home.ucenter/;
        #}
        location / {
                proxy_pass http://load_balance;
        }
        server_name proxy;
}
配置解释:
1)定义一个server集群load_balance,可以用域名,也可以直接用IP,(要注意不要加上http://).
2)用前一节讲的proxy_pass实现代理。把域名代理到集群名上面.

3)结束了,哈哈。简单吧。
单台server的设置:
1.down 表示单前的server暂时不参与负载
2.weight 默认为1.weight越大,负载的权重就越大。
3.max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误
4.fail_timeout:max_fails次失败后,暂停的时间。
5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力正常最小。
附上英文:
# weight = NUMBER - set weight of the server, if not set weight is equal to one.

#max_fails = NUMBER - number of unsuccessful attempts at communicating with the server within the time period (assigned by parameter fail_timeout) after which it is considered inoperative. If not set, the number of attempts is one. A value of 0 turns off this check. What is considered a failure is defined by proxy_next_upstream or fastcgi_next_upstream (except http_404 errors which do not count towards max_fails).

#fail_timeout = TIME - the time during which must occur *max_fails* number of unsuccessful attempts at communication with the server that would cause the server to be considered inoperative, and also the time for which the server will be considered inoperative (before another attempt is made). If not set the time is 10 seconds. fail_timeout has nothing to do with upstream response time, use proxy_connect_timeout and proxy_read_timeout for controlling this.

# down - marks server as permanently offline, to be used with the directive ip_hash.

# backup - (0.6.7 or later) only uses this server if the non-backup servers are all down or busy

分享到:
评论

相关推荐

    一个完整的nginx配置文件范例参考(含负载均衡)

    下面我们将深入探讨这个包含负载均衡配置的 Nginx 示例。 首先,配置文件的开头定义了 Nginx 运行的基本参数。`user nobody nobody;` 设置了 Nginx 的运行用户为 nobody,这意味着 Nginx 服务将以低权限用户身份...

    nginx_conf.zip

    《Nginx配置详解——基于ngnix.conf的真实范例》 在Web服务器领域,Nginx以其高效、稳定的特点,被广泛应用于各种网站和应用的前端代理与反向代理服务。本文将深入探讨Nginx的核心配置文件`nginx.conf`,通过分析一...

    深入解析Nginx:高性能Web服务器的技术原理与实战案例

    首先解释了 Nginx 是一个轻量级、高效的 Web 和反向代理服务器,具备处理大量并发请求的能力,接着展示了其模块化设计特点,涉及主要功能包括静态文件服务、反向代理、负载均衡、内容缓存等。随后讲解了 Nginx 的...

    LEMP构建高性能WEB服务器(第三版)

    2.提供NGINX常见配置范例含(虚拟主机,防盗链,Rewrite,访问控制,负载均衡等等) 3.将原版的xcache替换成EA,并提供相关简单调优脚本及配置文件。 4.PDF下载地址:[url]http://www.linuxtone.org/lemp/lemp.pdf[/url...

    apache集群范例

    还有其他独立的负载均衡软件如Nginx、HAProxy等,也可以与Apache配合使用。 2. **复制和同步技术**:保持多台服务器间的数据一致性至关重要。可以通过rsync、DRBD、Heartbeat等工具进行数据同步,或者使用专门的...

    lua也很强!!

    此外,Lua常用于网络服务器的配置和管理,例如Nginx就支持Lua模块,通过Lua可以动态处理HTTP请求,实现灵活的路由规则和负载均衡策略。 Lua的模块系统允许开发者通过require函数加载和复用代码,创建自己的库。比如...

    基于SpringBoot的小区运动中心预约管理系统的设计与实现_1p95h88y_210-wx-.zip

    同时,系统还应当考虑高并发情况下的负载均衡和请求分发,使用如Spring Cloud或Nginx等技术手段来实现。 该系统的开发还应当考虑代码的质量,编写单元测试和集成测试来确保代码的稳定性和可靠性。在文档方面,除了...

    谷粒商城项目超详细项目源代码_gulimall.zip

    为了保证系统的安全性和稳定性,谷粒商城项目的源代码中应该也会包含一些安全机制的实现,如防止SQL注入、XSS攻击、CSRF攻击的措施,以及应对高并发请求的负载均衡和流量控制策略。 最后,谷粒商城项目还可能会提供...

    7陈航-如何用云计算赋能万亿家居行业.pdf

    酷家乐的核心技术架构包括反向代理负载均衡Nginx,用于提高请求的处理能力,同时在渲染集群中实现多实例并行渲染,通过OSS、RDS、MongoDB、Redis、Kafka等云服务来支撑大规模的在线设计需求。这些服务作为云计算中的...

Global site tag (gtag.js) - Google Analytics