@H_404_1@我有几个服务器地址,如cdn1.website.com,cdn2.website.com,cdn3.website.com.他们每个人都持有simillar文件.
@H_404_1@请求来到我的服务器,我想将其重定向或重写为随机的cdn服务器.
可能吗 ?
可能吗 ?
最佳答案
您可以尝试使用split clients模块:
@H_404_1@
原文链接:https://www.f2er.com/nginx/434817.htmlhttp {
# Split clients (approximately) equally based on
# client ip address
split_clients $remote_addr $cdn_host {
33% cdn1;
33% cdn2;
- cdn3;
}
server {
server_name example.com;
# Use the variable defined by the split_clients block to determine
# the rewritten hostname for requests beginning with /images/
location /images/ {
rewrite ^ http://$cdn_host.example.com$request_uri? permanent;
}
}
}