Tengine基础8

2022-05-03 10:42:28 浏览数 (1)

案例分析

Nginx 很大的一个作用就是作为web前端进行负载均衡和反向代理,但负载均衡的一个关键点就是状态检查,因为不能把请求分配给有故障的后端服务器

下面对一个案例进行分析

代码语言:javascript复制
[root@i-1avyrt2d conf]# cat nginx.conf | grep -v "#" | grep -v "^$"  
user nginx nginx;
worker_processes  4;
error_log  /var/log/nginx/error.log error;
worker_rlimit_nofile 65535;
events {
	worker_connections  65535;
	use epoll;
}
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  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    include apps/proxy_tengine.conf;
}
[root@i-1avyrt2d conf]# cat apps/proxy_tengine.conf | grep -v "#" | grep -v "^$"  
    upstream test_apps {
        server x.x.x.x:80  max_fails=1 fail_timeout=10s weight=25;
        server y.y.y.y:80  max_fails=1 fail_timeout=10s  weight=25;
        server x.x.x.x:80  max_fails=1 fail_timeout=10s  weight=25;
        server y.y.y.y:80  max_fails=1 fail_timeout=10s  weight=25;
        check interval=5000 fall=5 rise=2 timeout=2000 default_down=false type=http;
        check_http_send "HEAD /health_status HTTP/1.0rnrn";
        check_http_expect_alive http_2xx http_3xx;
    }
    server {
        listen  80;
        server_name  *.boohee.com   _;
        keepalive_timeout  30; 
        location /nginx-status {
            stub_status on;
            access_log  off;
            allow z.z.z.z;
            allow i.i.i.i/28;
            deny all;
        }
	location /status {
        auth_basic      "input your name and passsword";
        auth_basic_user_file  apps/status.passwd;
        check_status;
        access_log off;
        allow all;
	}	
	location / {
	    proxy_pass http://test_apps;
            proxy_set_header X-Forwarded-For  $remote_addr;
	
	}
     }
[root@i-1avyrt2d conf]# ../sbin/nginx  -t -c /usr/local/nginx/conf/nginx.conf
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@i-1avyrt2d conf]# kill  -HUP `cat ../logs/nginx.pid `
[root@i-1avyrt2d conf]# 

0 人点赞