zoukankan      html  css  js  c++  java
  • 初探nginx负载均衡配置

    只简单说一下upstream的配置,如何进行负载均衡后续还需要多了解

    1.另准备一个配置文件命名为nginx_test.conf

    为了不污染原有的nginx.conf,提前复制一份配置文件做试验,然后启动nginx时加载nginx_test.conf

    启动命令:

    [root@localhost conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx_test.conf

    -c参数表示加载指定的配置文件,后面跟的是文件路径

    2.在http模块下添加upstream配置

        upstream tomcat
        {
          server localhost:8080;   # 对应server下location中添加的 proxy_pass
        } 
        upstream ApprPhD
        {
           server 192.168.0.1XX:3030;
        }
    server {
           listen   80;
           server_name  hanmk.com;
           location / {
           root /tmp/data/;
           autoindex on;
    }
    }
        server {
            listen    80 default_server;
            server_name demo.com ;
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
            # location / {
            #    root   html;
            #   index  index.html index.htm;
            # }
    
            location / {
            proxy_pass http://tomcat;   # 对应upstream为tomcat,访问本地tomcat
            }
    
            #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;
            #}
    
           location /jenkins {            
                  proxy_pass  http://tomcat;  #对应upstream为tomcat,访问本地tomcat中部署的jenkins
    
                  proxy_set_header        Host $host;
                  proxy_set_header        X-Real-IP $remote_addr;  #获取真实ip
                  proxy_connect_timeout   90;
                  proxy_send_timeout      90;
                  proxy_read_timeout      90;
                  proxy_buffer_size       4k;
                  proxy_buffers           4 32k;
                  proxy_busy_buffers_size 64k;
                  proxy_temp_file_write_size 64k;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#获取代理者的真实ip
                  proxy_redirect          off;
           }
           location /ApprPhD {          
                  proxy_pass http://ApprPhD;  # 对应upstream为ApprPhD,访问1XX服务器部署的ApprPhd
                  proxy_set_header        Host $host;
                  proxy_set_header        X-Real-IP $remote_addr;  #获取真实ip
                  proxy_set_header REMOTE-HOST $remote_addr;
                  proxy_connect_timeout   90;
                  proxy_send_timeout      90;
                  proxy_read_timeout      90;
                  proxy_buffer_size       4k;
                  proxy_buffers           4 32k;
                  proxy_busy_buffers_size 64k;
                  proxy_temp_file_write_size 64k;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#获取代理者的真实ip
                  proxy_redirect          off;
           }
    
        }
  • 相关阅读:
    out/host/linuxx86/obj/EXECUTABLES/aapt_intermediates/aapt 64 32 操作系统
    linux 查看路由器 电脑主机 端口号 占用
    linux proc进程 pid stat statm status id 目录 解析 内存使用
    linux vim 设置大全详解
    ubuntu subclipse svn no libsvnjavahl1 in java.library.path no svnjavahl1 in java.library.path no s
    win7 安装 ubuntu 双系统 详解 easybcd 工具 不能进入 ubuntu 界面
    Atitit.json xml 序列化循环引用解决方案json
    Atitit.编程语言and 自然语言的比较and 编程语言未来的发展
    Atitit.跨语言  文件夹与文件的io操作集合  草案
    Atitit.atijson 类库的新特性设计与实现 v3 q31
  • 原文地址:https://www.cnblogs.com/hanmk/p/9304252.html
Copyright © 2011-2022 走看看