我有一个域example.com,每天有200万次访问。 没有网站内容的这个域名,我只redirect(302)到其他域名,以获得我的促销费用。
但我不希望所有这2百万用户访问同一个网站,也许有一百万,我将redirect到aol.com,另外一百万,我将redirect到bestbuy.com。
如何configuration我的nginxredirect到不同的域? 如果有像“ ip_hash ”这样的东西,那会更好!
你可以像这样使用split_clients :
split_clients "${remote_addr}AAA" $destination { 50% aol.com; 50% bestbuy.com; } server { server_name example.com; return 302 http://$destination/; }
这有点不好意思,可能有一个更清晰的方法 – 但你可以使用随机索引模块从目录中select两个文件,每个文件包含一个延迟为零的元刷新到不同的URL。
所以你的nginxconfiguration将包含
location / { random_index on; }
而文档根目录将包含两个文件(比如aol.com.html和bestbuy.com.html ),其中包含类似的内容
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>example.com</title> <meta http-equiv="refresh" content="0;URL='http://aol.com/'" /> </head> <body> <p>This page has moved to a <a href="http://aol.com/"> aol.com</a>.</p> </body> </html>
支持元刷新的浏览器将立即redirect到元标记中的URL,因此用户将在短时间内看到该消息(如果有的话)。