Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a domain example.com and I have 2 million visits everyday. There is no website content for this domain, I only redirect(302) it to other domain to get my promotion fee.

But I don't want all these 2 million user to visit the same website, maybe for 1 million of them, I will redirect to aol.com, for another million, I will redirect to bestbuy.com.

How to config my nginx to redirect the to different domain? If there is something like "ip_hash", it would be better!

share|improve this question

2 Answers 2

You can use split_clients like this:

split_clients "${remote_addr}AAA" $destination {
              50%                 aol.com;
              50%                 bestbuy.com;

server {
    server_name example.com;
    return 302 http://$destination/;
share|improve this answer

This is a bit hacky and there might be a cleaner way -- but you could use the random index module to pick two files from a directory, each file containing a meta refresh with a delay of zero to different URLs.

So your nginx config would contain

location / {
    random_index on;

and the document root would contain two files (say aol.com.html and bestbuy.com.html) containing something like

<html xmlns="http://www.w3.org/1999/xhtml">    
    <meta http-equiv="refresh" content="0;URL='http://aol.com/'" />    
    <p>This page has moved to a <a href="http://aol.com/">

Browsers that support meta refresh will redirect to the URL in the meta tag immediately, so users will see the message for a very short time (if at all).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.