zoukankan      html  css  js  c++  java
  • nginx 负载

    准备服务器、域名、nginx程序

    服务器A:47.104.238.XX

    服务器B:39.105.126.XX

    域名:fz213.xxx.top

    nginx下载地址:http://nginx.org/en/download.html

    实现思路:域名的A记录指向服务器A,在服务器A上部署nginx,然后访问域名,重新跳转A或B服务器

    1、配置nginx.conf文件

    配置的主要思路:访问域名时,通过域名解析的A记录,找到对应的服务器,nginx此时捕获,走nginx配置文件,通过配置中的端口监控匹配对应的规则,转发到对应的服务器及端口

    a、在server节点上面增加upstream

    8032、8016分别对应的是网站的端口

    upstream iis.temp.fz.2021{
    server 39.105.126.xx:8032 weight=1;
    server 47.104.238.xx:8016 weight=1;
    }
    

    b、在server中配置监听端口,服务器名称

    由于80端口冲突,这里监听8017端口

     listen       8017;
     server_name  fz213.xxx.top;

    c、路由中配置upstream名称

     location / { 
                 proxy_pass http://iis.temp.fz.2021;
              }

    完整配置:

    #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;
    
        #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;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
        upstream iis.temp.fz.2021{ 
            server 39.105.126.xx:8032 weight=1;
            server 47.104.238.xx:8016 weight=1;
        }
        server {
            listen       8017;
            server_name  fz213.xxx.top;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                #root   html;
                #index  index.html index.htm;
                proxy_pass http://iis.temp.fz.2021;
            }
    
            #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;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }
    
    
        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    
        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    }
    

    2、启动nginx

    3、访问地址即可

    此时由于监控的是8017端口,所以域名后面需要加上8017

    即:fz213.xxx.top:8017

     去掉端口的访问方法:https://www.cnblogs.com/xiao-sheng/p/15415377.html

  • 相关阅读:
    keys命令的缺点
    redis与memcache的区别
    sql与nosql如何选择?
    MongoDB与MySql的区别
    linux环境搭建系列之memcached安装步骤
    linux环境搭建系列之tomcat安装步骤
    linux环境搭建系列之Apache ant安装步骤
    linux环境搭建系列之jdk安装
    虚拟机安装教程(linux、centOS)
    memcached解压报错gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now的解决方法
  • 原文地址:https://www.cnblogs.com/xiao-sheng/p/15415260.html
Copyright © 2011-2022 走看看