美文网首页
nginx实现负载均衡

nginx实现负载均衡

作者: MwinxAxniwM | 来源:发表于2018-09-12 16:01 被阅读0次

    nginx实现负载均衡

    • http节点中添加
        upstream backend  {
                server  192.168.1.108:80;
                server  192.168.1.109:80;
            }
    
    • 修改server节点:
        location / {
            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_buffering off;
            proxy_pass http://backend;
        } 
    
    • 多种应用按域名分发:
        upstream django  {
                server  192.168.1.108:80;
                server  192.168.1.109:80;
                server  192.168.1.110:80;
                server  192.168.1.111:80;
        }
        upstream php  {
                server  192.168.1.112:80;
                server  192.168.1.113:80;
        }
    
        server {
            listen       80;
            server_name  www.zhuangyan.cn;
            #charset koi8-r;
            #access_log  logs/host.access.log  main;
            location / {
                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_buffering off;
              proxy_pass http://php;
            }
           
        }
    
        server {
            listen       80;
            server_name  app.zhuangyan.cn;
            location / {
              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_buffering off;
              proxy_pass http://django;
          }
          location ~/static/ {
                root  /home/django/;
                index  index.html index.htm;
          }      
        }
    

    相关文章

      网友评论

          本文标题:nginx实现负载均衡

          本文链接:https://www.haomeiwen.com/subject/wrzvgftx.html