0

Is it possible to configure nginx in the way it sends request to n well known locations and returns response as soon as it gets 20x from one of them?

If it helps, I have 100% guarantee that either exactly one host responds or there will be no successful response at all.

3
  • 1
    Can you elaborate on what 'gets 20x' is? A proper configured load balancing pool will remove servers not responding within a timeframe. Commented Feb 21, 2016 at 13:06
  • Yeah, the keyword is: loadbalancing. I just realized the only thing I need to do is to set up load balancer in front of that n server and nginnx will do the rest. Thanks. Commented Feb 21, 2016 at 13:28
  • OK, sound good. I'll add an answer with a setup I have, adding a timeout parameter. Commented Feb 21, 2016 at 13:35

1 Answer 1

3

You can setup a load balancing pool where a server not responding within a timeframe is removed. Using sticky sessions using ip_hash where the same ip-address goes back to the same server. Useful for maintaining sessions if sessioninformation is not shared across servers. nginx have a well documented page with the various options.

http {
    upstream my_pool {
        ip_hash;
        server 1.2.3.4 weight=3 max_fails=3 fail_timeout=20s;
        server 1.2.3.5 weight=4 max_fails=3 fail_timeout=20s;
        server 1.2.3.6 weight=3 max_fails=3 fail_timeout=20s;
    }

    server {
        listen 80 ;
        server_name domain.org www.domain.org;

        location / {
            proxy_set_header HOST $host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://my_pool;
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.