4

I would like to redirect clients on a round robin basis with nginx if that's possible. However, most, if not all, of my research proxy the client rather than redirect.

I've seen this question and it's exactly what I'm trying to do, but round robin (or other strategies in the future e.g. least connections) instead of random.

Is there an elegant way to do it within nginx, or do I really have to resort to proxying to myself?

For reference, here is the implementation from the linked question:

upstream boxes {
        server 127.0.0.1:46011;
        server 127.0.0.1:46012;
}

server {
        listen 46011;
        return 302 http://box11.example.com$request_uri;
}

server {
        listen 46012;
        return 302 http://box12.example.com$request_uri;
}

server {
        listen 80;
        server_name example.com;

        location / {
                proxy_pass http://boxes;
        }
}
Aloha
  • 286
  • 4
  • 15
  • The code above works well for my application. It does do round-robin redirects. My main question is whether there's a more elegant way of implementing it, preferably without proxying. – Aloha Sep 25 '20 at 07:13
  • 1
    Most people don't want their web site users to know they are being A/B tested, which is why most everyone proxies. Though this setup works, it doesn't really make much sense. – Michael Hampton Sep 25 '20 at 07:34
  • @MichaelHampton I agree. This is for internal uses. I'm interfacing with a system that I'm not allowed to change. – Aloha Sep 25 '20 at 07:39

0 Answers0