Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a domain 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, for another million, I will redirect to

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

You can use split_clients like this:

split_clients "${remote_addr}AAA" $destination {
              50%       ;
              50%       ;

server {
    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 and containing something like

<html xmlns="">    
    <meta http-equiv="refresh" content="0;URL=''" />    
    <p>This page has moved to a <a href=""></a>.</p> 

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.