Nginx Retry of Requests ( Nginx - Haproxy Combination )

Posted by vaibhav on Server Fault See other posts from Server Fault or by vaibhav
Published on 2012-03-11T23:34:49Z Indexed on 2012/12/08 17:07 UTC
Read the original article Hit count: 469

Filed under:
|
|

I wanted to ask about Nginx Retry of Requests. I have a Nginx running at the backend which then sends the requests to HaProxy which then passes it on the web server and the request is processed. I am reloading my Haproxy config dynamically to provide elasticity. The problem is that the requests are dropped when I reload Haproxy. So I wanted to have a solution where I can just retry that from Nginx. I looked through the proxy_connect_timeout, proxy_next_upstream in http module and max_fails and fail_timeout in server module. I initially only had 1 server in the upstream connections so I just that up twice now and less requests are getting dropped ( only when ) have say the same server twice in upstream , if I have same server 3-4 times drops increase ).

So , firstly I wanted to now , that when a request is not able to establish connection from Nginx to Haproxy so while reloading it seems that conneciton is seen as error and straightway the request is dropped .

So how can I either specify the time after the failure I want to retry the request from Nginx to upstream or the time before which Nginx treats it as failed request.

( I have tried increaing proxy_connect_timeout - didn't help , mail_retires , fail_timeout and also putting the same upstream server twice ( that gave the best results so far )

Nginx Conf File

upstream gae_sleep {

server 128.111.55.219:10000;

}

server {

listen 8080;
server_name 128.111.55.219;
root /var/apps/sleep/app;
# Uncomment these lines to enable logging, and comment out the following two
#access_log  /var/log/nginx/sleep.access.log upstream;
error_log  /var/log/nginx/sleep.error.log;
access_log off;
#error_log /dev/null crit;

rewrite_log off;
error_page 404 = /404.html;
set $cache_dir /var/apps/sleep/cache;



location / {
  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;
  proxy_pass http://gae_sleep;
  client_max_body_size 2G;
  proxy_connect_timeout 30;
  client_body_timeout 30;
  proxy_read_timeout 30;
}

location /404.html {
  root /var/apps/sleep;
}

location /reserved-channel-appscale-path {
  proxy_buffering off;
  tcp_nodelay on;
  keepalive_timeout 55;
  proxy_pass http://128.111.55.219:5280/http-bind;
}

}

© Server Fault or respective owner

Related posts about nginx

Related posts about haproxy