Nginx配置upstream实现负载均衡

  • A+
所属分类:运维教程

如果Nginx没有仅仅只能代理一台服务器的话,那它也不可能像今天这么火,Nginx可以配置代理多台服务器,当一台服务器宕机之后,仍能保持系统可用。具体配置过程如下:

  • 在http节点下面,添加upstream的节点。
  1. upstream birdteam {
  2. server 192.168.18.251;
  3. server 192.168.18.252;
  4. }
  • 将server节点下的location节点中的proxy_pass配置为http://+upstream名称,如http://birdteam。
  1. location / {
  2. proxy_pass http://birdteam;
  3. }
  • 现在负载均衡就初步完成了。upstream会按照轮询方式进行负载,每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器宕掉了,可以自动剔除。虽然这种方式简便、成本低廉。但缺点是:可靠性低和负载分配不均衡。适用图片服务器集群和纯静态页面服务器集群。
  • 问答中心
  • 微信小程序扫一扫
  • weinxin
  • 微信公众
  • 微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:25   其中:访客  25   博主  0

    • avatar best web hosting company

      Hi, I do think this is an excellent web site. I stumbledupon it ;) I will return yet again since
      i have bookmarked it. Money and freedom is the best way to change, may you be rich and continue to guide other people.

      • avatar web hosting reviews

        Hello there! I could have sworn I’ve been to this website before but after browsing through some of the post I realized it’s new
        to me. Nonetheless, I’m definitely delighted I found it and
        I’ll be book-marking and checking back often!

        • avatar try this site

          I genuinely enjoy reading through on this site, it has got fantastic posts.

          • avatar best web hosting sites

            Hey there just wanted to give you a quick heads up. The text in your post
            seem to be running off the screen in Opera.

            I’m not sure if this is a formatting issue or something
            to do with browser compatibility but I thought I’d post to let you know.
            The design and style look great though! Hope you get the issue resolved soon. Cheers

            • avatar web hosting sites

              Your style is really unique in comparison to other
              people I have read stuff from. Many thanks for posting when you’ve got the opportunity,
              Guess I’ll just bookmark this blog.