• 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

  • 相关阅读:
    Python环境搭建后,多种方式的使用进行程序的执行。
    Visual Studio 2017进行Python开发环境的搭建,使用VS2017进行python代码的编写。
    Linux Ubuntu运行线程程序出现undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’错误。
    计算机二级-C语言-程序填空题-190107记录
    2018/03/08 每日一学PHP 之 常量defind 和 const区别
    H5手机页面剖析
    jQuery(三)
    jQuery(二)
    jQuery(一)
    JS构造函数(便于理解,简易)
  • 原文地址:https://www.cnblogs.com/xiao-sheng/p/15415260.html
Copyright © 2020-2023  润新知