zoukankan      html  css  js  c++  java
  • nginx负载均衡配置一(*)

    一、前提

    1:系统linux(centos)

    2:nginx代理服务器(web:192.168.1.10  proxy.abc.com)

    3:nginx后台服务器(web1:192.168.1.11 www.abc.com  web2:192.168.1.12 backend.abc.com)

    二、配置(192.168.1.10)

    1:配置/usr/local/nginx/config/nginx.conf

         将server{}删除掉,通过include config.d/*.conf 引入所有的server配置

         在nginx.conf最后添加以下几行: 

    upstream abc{
                   #server 127.0.0.1:8000;         ###通过IP## 
                   #server 127.0.0.1:8001;
                   server www.abc.com:8000;     ###通过域名###
                   server backend.abc.com:8001;
    }
    include conf.d/*.conf; 
     

    2:配置

    /usr/local/nginx/config/config.d/proxy.conf

    server {
            listen       80;
            server_name  proxy.xiaohuideng.com;
    
            #charset koi8-r;
            #access_log  logs/host.access.log  main;
            location / {
                index  index.html index.htm;
    
                    proxy_set_header Host $http_host; ###默认是以IP为负载(proxy_set_header Host $host;)
                    proxy_buffering off;
                 proxy_set_header X-Real-IP $remote_addr; ##不过滤掉真实请求IP地址 proxy_pass http:
    //abc; ###引入upstream所定义的名字 } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
    三、重启nginx (192.168.1.10)
    /usr/local/nginx/sbin/nginx -t ##测试配置是否OK
    /usr/local/nginx/sbin/nginx -s reload ###重新加载配置


    四、查看效果
    在远程的PC机浏览器上访问 http://proxy.abc.com看是不是得到backend.abc.com与www.abc.com的页面切换
  • 相关阅读:
    Luogu P4727 [HNOI2009]图的同构记数
    ARC 101 E
    JSOI2019 Round2 游记
    JSOI2019 Round1(十二省联考)游记
    Technocup 2019
    Codeforces Round #533 (Div. 2)比赛总结
    学习链接
    2018.12.29-2018.1.9安师大附中集训
    关于考试
    NOIP2018提高组 游记
  • 原文地址:https://www.cnblogs.com/amuge/p/6028795.html
Copyright © 2011-2022 走看看