nginx配置web容器實現自動剔除異常(失敗)的服務


要實現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內該服務不會被請求到)。


參數說明:

  • down 表示單前的server暫時不參與負載
  • weight 默認為1.weight越大,負載的權重就越大。
  • max_fails :允許請求失敗的次數默認為1.當超過最大次數時,返回proxy_next_upstream 模塊定義的錯誤
  • fail_timeout:max_fails次失敗后,暫停的時間。
  • backup: 其它所有的非backup機器down或者忙的時候,請求backup機器。所以這台機器壓力會最輕。


下面為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; } } }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM