zoukankan      html  css  js  c++  java
  • upstream模块介绍

    upstream模块介绍

    Nginx的负载均衡功能依赖于ngx_http_upsteam_module模块,所支持的代理方式包括proxy_pass、fastcgi_pass、memcached_pass等,新版Nginx软件支持的方式所以增加。主要针对proxy_pass代理。

    ngx_http_upstream_module模块有允许Nginx定义一组或多组服务组,使用的可以通过proxy_pass代理方式吧网站的请求发送到事先定义好的对应upstream组的名字上,具体写法为proxy_pass http://www_server_pools,期中www_server_pools就是一个uupstream节点服务组名字

    ngx_http_upsteam_module模块官方地址:

    http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream

    基本的upstream配置案例

    #准备环境
    cp /application/nginx/conf/nginx.conf{,.bak.before.lb}
    cd /application/nginx/conf/
    
    vim /application/nginx/conf/nginx.conf
    
    #####web01 web02 web03
     worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        server {
            listen       80;
            server_name  www.etiantian.org;
            location / {
                root   html/www;
                index  index.html index.htm;
            }
            access_log  logs/access_www.log  main;
        }
            server {
            listen       80;
            server_name  bbs.etiantian.org;
            location / {
                root   html/bbs;
                index  index.html index.htm;
            }
            access_log  logs/access_bbs.log  main;
        }
    }
    
    ###创建环境
    mkdir -p /application/nginx/html/{www,bbs}
    for dir in www bbs;do echo "`ifconfig eth0|egrep -o "10.0.0.[0-9]+"` $dir" >/application/nginx/html/$dir/bingbing.html;done
    
    /application/nginx/sbin/nginx -t
    /application/nginx/sbin/nginx -s reload
    
    curl 10.0.0.7/bingbing.html 
    curl 10.0.0.8/bingbing.html
    curl 10.0.0.9/bingbing.html
    
    ######lb01负载均衡服务器
    
    cd /application/nginx/conf/
    cp /application/nginx/conf/nginx.conf{,.bak.before.lb}
    cd /application/nginx/conf/
    
    vim /application/nginx/conf/nginx.conf
    
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        
        
        upstream server_pools { 
             server 10.0.0.7;
             server 10.0.0.8;
             server 10.0.0.9;
        }       
        
        server { 
           listen       80;
           server_name  www.etiantian.org;
           location / {
            proxy_pass http://server_pools; 
           }
        }
    }
    
     /application/nginx/sbin/nginx -t
    
     /application/nginx/sbin/nginx -s reload
    
    #在lb01测试
    curl 10.0.0.5/bingbing.html
    
    curl 10.0.0.7/bingbing.html
      curl 10.0.0.8/bingbing.html
      curl 10.0.0.9/bingbing.html
    基本的upstream配置案例
  • 相关阅读:
    虚拟机vmware的连接方式以及IP端口,协议等概念
    python3爬虫--shell命令的使用和firefox firebug获取目标信息的xpath
    numpy的基本用法
    scrapy模拟请求头
    (1)python Scrapy爬虫框架
    flutter ui
    dart 类
    dart 基础
    黑苹果镜像下载地址
    android9.0请求异常
  • 原文地址:https://www.cnblogs.com/zhaojingyu/p/9073399.html
Copyright © 2011-2022 走看看