【问题标题】:nginx prevent to request form server with height timeout response?nginx 阻止请求具有高度超时响应的表单服务器?
【发布时间】:2016-06-07 15:37:28
【问题描述】:

我有一个 nginx 服务器,它将请求从一个 URL 传递到其他一些服务器,类似于:

upstream main {
    server {{OPENSHIFT_INTERNAL_IP}}:15010 weight=1 fail_timeout=1s;
    server {{OPENSHIFT_INTERNAL_IP}}:15011 weight=1 fail_timeout=1s;
    server {{OPENSHIFT_INTERNAL_IP}}:15012 weight=1 fail_timeout=1s;
    server {{OPENSHIFT_INTERNAL_IP}}:15013 weight=1 fail_timeout=1s;

    keepalive 300;

    }

location  ~* ^/(.*) {
         proxy_pass http://main;
         #proxy_read_timeout 5s;
         proxy_connect_timeout 5s;
        }

,所以我需要拒绝向繁忙的服务器发送请求,那么我该如何防止向过载的服务器发送请求。

【问题讨论】:

标签: nginx connection-timeout


【解决方案1】:

我在 nginx 中使用了 Fair 模块:

git clone https://github.com/gnosek/nginx-upstream-fair.git

cd nginx-${NGINX_VERSION}   
./configure\
   --prefix=${OPENSHIFT_HOMEDIR}/app-root/runtime/srv/nginx\
   --with-pcre=$OPENSHIFT_TMP_DIR/pcre-${PCRE_VERSION}\
   --with-zlib=$OPENSHIFT_TMP_DIR/zlib-${ZLIB_VERSION}\
   --with-http_ssl_module\
   --with-http_geoip_module\
   --with-http_realip_module \
   --with-http_addition_module \
   --with-http_sub_module\
   --with-http_dav_module \
   --with-http_flv_module \
   --with-http_mp4_module \
   --with-http_gunzip_module\
   --with-http_gzip_static_module \
   --with-http_random_index_module \
   --with-http_secure_link_module\
   --with-http_stub_status_module \
   --with-mail \
   --with-mail_ssl_module \
   --with-file-aio\
   --with-ipv6  \
   --add-module=$OPENSHIFT_TMP_DIR/nginx-upstream-fair\

通过这个配置:

upstream main {
    fair;
    server {{OPENSHIFT_INTERNAL_IP}}:15010 weight=1 fail_timeout=1s; #diy-tornado4ss.rhcloud.com
    #server {{OPENSHIFT_INTERNAL_IP}}:15011 weight=1 fail_timeout=1s; #diy2-elasa2.rhcloud.com
    server {{OPENSHIFT_INTERNAL_IP}}:15012 weight=1 fail_timeout=1s; #diy-phantomjs4so.rhcloud.com
    #server {{OPENSHIFT_INTERNAL_IP}}:15013 weight=1 fail_timeout=1s;
    #max_connections 3;
    keepalive 2100;

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 2014-12-18
    • 2016-09-08
    • 1970-01-01
    • 2019-01-18
    • 2017-06-06
    • 1970-01-01
    相关资源
    最近更新 更多