要实现nginx配置web容器实现自动剔除异常的服务,主要在nginx的conf下的nginx.conf文件的upstream中配置信息。
nginx负载均衡可以参考文章:https://www.52jingya.com/aid9.html
nginx配置web容器实现自动剔除异常(失败)的服务
具体内容如下:
upstream my_server { server 127.0.0.1:8080 weight=1 max_fails=1 fail_timeout=60s; server 127.0.0.1:8088 weight=1 max_fails=1 fail_timeout=60s; server 127.0.0.1:8086 weight=7 max_fails=1 fail_timeout=60s down; server 127.0.0.1:8087 weight=7 max_fails=1 fail_timeout=60s backup; }说明:
上面配置的是同一台服务器,负载了2个tomcat容器,端口分别为8080和8088。请求失败1次后,服务剔除60s(在60s内该服务不会被请求到)。
参数说明:
下面为nginx.conf的完整配置
#user nobody; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 45; #gzip on; upstream my_server { server 127.0.0.1:8080 weight=7 max_fails=1 fail_timeout=60s; server 127.0.0.1:8088 weight=7 max_fails=1 fail_timeout=60s; server 127.0.0.1:8086 weight=7 max_fails=1 fail_timeout=60s down; server 127.0.0.1:8087 weight=7 max_fails=1 fail_timeout=60s backup; } server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location ~ .*\.(jsp|syy|do|html)$ { proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://my_server; client_max_body_size 5m; } #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; } } }
以上为我亲自配置,测试后得出的结论。
感谢您的阅读,希望对您有帮助,本文版权归 #惊讶# 所有