Linux Nginx配置负载均衡

安装nginx_upstream_check_module模块
rpm -ivh patch-2.7.1-12.el7_7.x86_64.rpm --force --nodeps
cd /app/nginx/nginx-1.17.3
修改/tmp/目录
patch -p1 < /tmp/nginx_upstream_check_module-master/check_1.16.1+.patch
配置Nginx
./configure --prefix=/app/nginx --add-module=/tmp/nginx_upstream_check_module-master/ --with-http_stub_status_module --with-http_ssl_module --with-pcre
编译安装
make && make install
安装sticky模块
unzip nginx-sticky.zip
cd /app/nginx/nginx-1.17.3
配置Nginx
./configure --prefix=/app/nginx --add-module=/tmp/nginx_upstream_check_module-master/ --add-module=/tmp/nginx-sticky/ --with-http_stub_status_module --with-http_ssl_module --with-pcre
编译安装
make
拷贝编译出来的二进制文件到nginx的sbin目录
/bin/cp -rf ./objs/nginx /app/nginx/sbin/nginx
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;

    #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;
    server_tokens off;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
	
	upstream web {
		sticky;
		//按实际配置两套应用的IP和port
		server IP:port weight=1;
		server IP:port weight=2;
		check interval=3000 rise=2 fall=5 timeout=1000 type=http;
		check_http_send "HEAD / HTTP/1.0\r\n\r\n";
		check_http_expect_alive http_2xx http_3xx http_4xx ;
	}

    server {
    	//按实际配置port
		listen   port ssl;
        server_name  localhost;
	
		ssl_certificate      XXXserver.crt;
        ssl_certificate_key  XXXserver.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
		
		//按实际配置应用目录
		location ^~/XXX {
			alias   /app/nginx_project/XXX;
			index  index.html index.htm;
       	}
	        
	    //按实际配置应用目录
		location ^~/XXXX {
 	       	client_max_body_size  1024m;
           	client_body_buffer_size 5m;
            proxy_connect_timeout 3600s;
           	proxy_send_timeout 3600s;
           	proxy_read_timeout 3600s;
			proxy_set_header Host $host:$server_port;
          	proxy_set_header X-Real-IP $remote_addr;
          	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
			proxy_pass https://web/XXXX;
			# proxy_next_upstream    error timeout  http_500 http_502 http_503 http_504  invalid_header;  # nginx自带后端检测
        }
		
		##显示后端server池中server的健康状态
		location /nastatus {
           check_status;
           access_log off;
           #allow 172.1.1.1;
           #deny all;
        }

		
        #charset koi8-r;
        #access_log  logs/host.access.log  main;

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

        #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;
        }
 
         }

}

查看负载均衡服务的状态
https://IP:port/nastatus

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值