0

I've configured nginx as a reverse proxy for downloading software artifacts (e.g. JAR files) and want to speed it up by proxying each request to multiple upstream servers in parallel.

The following currently works: with nginx running at localhost:8080, I request localhost:8080/com/foo/bar.jar, nginx checks serially for the file com/foo/bar.jar at each host in a pre-configured list (e.g. repo1.org/com/foo/bar.jar, repo2.org/com/foo/bar.jar, etc.), and returns the first matching artifact (i.e. first to return status 200).

The config below makes this work for repos at maven.org and osgeo.org:

events {}
http {
    server {
        listen 8000;
        location / {
            proxy_pass https://repo1.maven.org/maven2/;
        }
    }
    server {
        listen 8001;
        location / {
            proxy_pass https://repo.osgeo.org/repository/release/;
        }
    }
    upstream repositories {
        server localhost:8000;
        server localhost:8001;
    }
    server {    
        location / {
            proxy_next_upstream error timeout http_404;
            proxy_pass http://repositories;
        }
    }
}

To decrease latency, I'd like for nginx to run the requests in parallel, return the first one that gives a 200, and otherwise return error code 404.

I'm not sure which directives (if any) can enable this kind of behavior. I appreciate any tips.

Alex Klibisz
  • 1,313
  • 1
  • 14
  • 21

1 Answers1

0

According to nginx documentation it is possible using nginx plus. As stated in nginx plus documentation, the load balancing method you are searching for is the Least Time method.

If you are using the default nginx you can use documentation nginx

tldr;

  • Default load balancing configuration (Round Robin)
  • Least connected load balancing
  • Weighted load balancing
  • Session persistence
Danizavtz
  • 3,166
  • 4
  • 24
  • 25