zoukankan      html  css  js  c++  java
  • Nginx 配置负载均衡

    1:接上一篇博客:Nginx 源码安装

    http://www.cnblogs.com/xiaoit/p/4062458.html

    2:准备另外两台相同的配置机器

    搭建Nginx的服务器主:101.69.178.208

    负载均衡机器Nginx1:101.69.178.219

    负载均衡机器Nginx2:61.153.100.239

    3:查看主服务器上nginx.conf

    cd /gechong/ruanjian/Nginx/conf
    

    新装完Nginx的conf文件如下:

    #user  nobody;
    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
    	
        server {
            listen       80;
            server_name  localhost;
    
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
        }
    
    }
    

    做如下调整


    #user nobody;
    worker_processes 1;

    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;


    events {
    worker_connections 1024;
    }


    http {

    upstream 101.69.178.208 {
    server 61.153.100.239:80;
    server 101.69.178.219:80;
    }

    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;

    server {
    listen 80;
    server_name 101.69.178.208;


    location / {
    # root html;
    # index index.html index.htm;
    #}
    proxy_pass http://101.69.178.208;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    }
    }

    4:修改Nginx1和Nginx2机器上的nginx.conf 配置文件

    cd /gechong/ruanjian/Nginx/conf
    

    #user nobody;
    worker_processes 1;

    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;


    events {
    worker_connections 1024;
    }


    http {

    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;

    server {
    listen 80;
    server_name 101.69.178.208;

    location / {
    root html;
    index index.html index.htm;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    }
    }

    5:简单修改index.html以区别两台机器

    6:测试负载均衡

    浏览器访问:http://101.69.178.208/

    7:测试成功。。。

    但是单独拿出来一台机器做转发,感觉有点浪费资源,下一节将说明如何配置转发机器也提供访问。

     

  • 相关阅读:
    [leetcode] 17. 电话号码的字母组合
    C++17 Fold Expressions
    多线程----NSOperation
    CGD---1--开辟并发新线程
    彻底解决_OBJC_CLASS_$_某文件名", referenced from:问题(转)
    ios 内存使用陷阱 和imageNamed 、imageWithContentsOfFile:(转)
    (转)unbalanced calls to begin/end appearance transitions for uiviewcontroller的解决方法
    ios开发种证书
    使用CAShapeLayer与UIBezierPath画出想要的图形
    定位子字符串的位置
  • 原文地址:https://www.cnblogs.com/xiaoit/p/4069459.html
Copyright © 2011-2022 走看看