共计 2823 个字符,预计需要花费 8 分钟才能阅读完成。
大家都晓得,前段 nginx 做反代,如果后端服务器宕掉的话,nginx 是不能把这台 realserver 提出 upstream 的,所以还会有申请转发到后端的这台 realserver 下面去,尽管 nginx 能够在 localtion 中启用 proxy_next_upstream 来解决返回给用户的谬误页面,办法在:http://www.linuxyan.com/web-s…
- 首先去这里下载 nginx 的模块 https://github.com/yaoweibin/…
- 上面是 nginx 打上模块补丁的装置
$ wget http://nginx.org/download/nginx-1.16.1.tar.gz’$ tar -xzvf nginx-1.16.1.tar.gz
$ cd nginx-1.16.1/
$ patch -p1 < /path/to/nginx_http_upstream_check_module/check.patch
注:因 nginx 版本更新,1.2 以上版本的 nginx,补丁为 check_1.16.1+.patch
$ ./configure --add-module=/data/nginx_upstream_check_module-master --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --add-module=/data/brotli/ngx_brotli --add-module=/data/echo-nginx-module-0.61
$ make
$ mv /data/nginx/sbin/nginx /tpm/
$ mv obj/nginx /data/nginx/sbin/
之后在 nginx.conf 配置文件外面的 upstream 退出健康检查,如下:
[root@81-nginx-test xxxx]# cat up.conf
upstream ser{
ip_hash;
server 192.168.0.47:8090 max_fails=2 fail_timeout=10s;
server 192.168.0.48:8090 max_fails=2 fail_timeout=10s;
check interval=5000 rise=1 fall=5 timeout=4000;
keepalive 20000;
}
这里上面加的这句话我解释下,interval 检测间隔时间,单位为毫秒,rsie 申请 2 次失常的话,标记此 realserver 的状态为 up,fall 示意申请 5 次都失败的状况下,标记此 realserver 的状态为 down,timeout 为超时工夫,单位为毫秒。在 server 段外面能够退出查看 realserver 状态的页面
[root@81-nginx-test xxxx]# cat a.conf
####uat-skpay-backmanage.xxxx.com
server {
listen 80;
server_name back.xxxx.com;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
#add_header X-Frame-Options SAMEORIGIN;
index index.html;
access_log /data/ser.log;
location / {if ($request_method !~ ^(GET|POST|PUT|DELETE|HEAD|OPTIONS)$) {return 403;}
#proxy_pass http://service-backmanage_uat;
#proxy_pass http://192.168.0.48:8090/backmanage/;
proxy_pass http://ser;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffering on;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_max_temp_file_size 1024m;
}
location /nstatus {
check_status;
access_log off;
allow all;
}
}
####uat-skpay-backmanage.xxxx.com
server {
listen 80;
server_name dev-back.xxxx.com;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
#add_header X-Frame-Options SAMEORIGIN;
index index.html;
access_log /data/ser.log;
location / {if ($request_method !~ ^(GET|POST|PUT|DELETE|HEAD|OPTIONS)$) {return 403;}
#proxy_pass http://service-backmanage_uat;
#proxy_pass http://192.168.0.48:8090/backmanage/;
proxy_pass http://ser;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffering on;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_max_temp_file_size 1024m;
}
location /nstatus {
check_status;
access_log off;
allow all;
}
}
正文完