博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx 负载均衡
阅读量:4286 次
发布时间:2019-05-27

本文共 1828 字,大约阅读时间需要 6 分钟。

代理机器:192.168.163.128
后端机器:192.168.163.129和192.168.163.131
以上三台机器都搭建了nginx
1、修改index.html,区别后端机器

192.168.163.129和192.168.163.131上的/usr/local/nginx/html/index.html中,修改Welcome to nginx 为Welcome to nginx129和Welcome to nginx131以作这两台机器的区别

2、nginx.conf配置

http模块中配置以下信息:

http {

    include       mime.types;
    default_type  application/octet-stream;
    #include /usr/local/nginx/conf/reverse-proxy.conf;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    upstream 123.tk{ #域名配置
        server 192.168.163.129:80 weight=1;  #第一台后端服务器,权重为1
        server 192.168.163.131:80 weight=1; #第二台后端服务器,权重为1
    }
    #keepalive_timeout  0;
    keepalive_timeout  65;
     gzip on;
    client_max_body_size 50m; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户
    client_body_buffer_size 256k;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    proxy_connect_timeout 300s; #nginx跟后端服务器连接超时时间(代理连接超时)
    proxy_read_timeout 300s; #连接成功后,后端服务器响应时间(代理接收超时)
    proxy_send_timeout 300s;
    proxy_buffer_size 64k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
    proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
    proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
    proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘
    proxy_ignore_client_abort on; #不允许代理端主动关闭连接
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            proxy_pass http://123.tk;    #访问的域名,即upstream的name
            proxy_redirect default;
            root   html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

3、分别启动这三台的nginx

4、在代理服务器上用浏览器多次访问123.tk,可以发现会随机的访问到129或131的nginx页面

转载地址:http://hdxgi.baihongyu.com/

你可能感兴趣的文章
nodejs之异常的处理
查看>>
nodejs之参数的接收GET 和POST
查看>>
nodejs之异步流程控制ASYNC
查看>>
nodejs之npm的使用、nvm
查看>>
nodejs之express(一)简单实现路由
查看>>
swift中KVO的使用和注意事项、属性观察器
查看>>
swift之GCD的使用
查看>>
swift之UIAlertController
查看>>
swift之视频播放AVKIT、AVPlayerViewController、音频录制和播放
查看>>
android之通知Notification
查看>>
android 之常用功能发短信、接受短信
查看>>
android 之意图Intent的使用
查看>>
android之内容观察者ContentResolver
查看>>
android之延迟执行的几种方法
查看>>
android保存内容到xml中、解析xml
查看>>
android 之从操作sqlite
查看>>
adroid之加密算法md5
查看>>
android之drawable文件的设置selector、shape
查看>>
android之手势、touch事件流程、事件传递机制
查看>>
android之res/values、国际化
查看>>